On Sat, May 16, 2015 at 7:19 PM, Alexander Praetorius <[email protected]>
wrote:

> I always imagined some nice readable way of specifying dependencies of
> "serial" and "parallel" pars of the process and how they "fork" and "merge
> back into each other.
>

I'll let someone else answer the other aspects of your question, but for
this part, async.auto I find is awesome (it's my most-used part of the
library).

You basically specify things that either have no dependencies, or depend on
previous data/functions. Here's an example (real world) usage from our app:

        async.auto({
            complete_task: function (cb) {
                if (!req.body.top_performer) return cb();
                notifications.complete_task("company", employee.company_id,
"top_performer_badge", cb);
            },
            employee: function (cb) {
                api.model.employees.update(employee, req.body, cb);
            },
            roles: function (cb) {
                api.model.roles.get_by_company_id(employee.company_id, cb);
            },
            ideal_calc: ['roles', function (cb, data) {
                async.each(data.roles, function (role, cb) {
                    iccalc.perform_for_role(role.id, cb);
                }, cb);
            }],
            match_recalc: ['ideal_calc', function (cb) {

match_recalculator.recalculate_for_company(employee.company_id, cb);
            }],
        }, function (err) {
            if (err) {
                console.error("Error updating employee: ", err);
                return res.send(500);
            }
            return res.send(200);
        })

As you can see there, ideal_calc depends on 'roles' and match_recalc
depends on 'ideal_calc'. The rest can be executed in parallel, and the
async library takes care of that for you.

Hope that helps,

Matt.

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAPJ5V2bWRtp2CrNuQ%3DGDpz9gsf6Uzyf%3DhuG6XNDURf%2ByUm%3Dqew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to