News for hackers. Stuff that matters.
Re:JavaScript: It’s Not Just for Browsers Any More by rictic on Saturday March 06, 2010 @04:12AM (#1171353)
Nope, no locks needed in Node. This is one of the little joys of javascript: no threading at all. None. With Web Workers you can have processes, but there isn't shared state; everything is done through message passing.

All parallelism is cooperative in javascript, meaning that you don't have to worry about control flow switching out from under you at arbitrary points, just when you explicitly yield it by returning from an event handler or from the top level of your program.

Finally, to answer the grandparent question, the easiest answer is a promise group. A promise group is basically a promise that emits a success event once all of its child promises have emitted success events. There are a few implementations floating around, though it's just a handful of lines of code to write and makes for a good exercise.

So assuming that A and B are rewritten to return promises (or wrapped, I believe that isaacs has a library which will wrap functions which take a callback to return a promise instead), you can do the following:

    var promise_a = do_A();
    promise_a.onSuccess(do_C);
    var promise_b = do_B();
    promise_b.onSuccess(do_D);

    var promise_group = new PromiseGroup([promise_a, promise_b]);
    promise_group.onSuccess(do_E);
Re:JavaScript: It’s Not Just for Browsers Any More by scotty79 on Saturday March 06, 2010 @06:07AM (#1171403)
> Finally, to answer the grandparent question

I don't event have a kid! ;-)

Thank you, that was the thing I was looking for. My question now: What happens if one of the promises fails? Is a promise group disposed then? Solution offered by Periodic would wait forever.

Re:JavaScript: It’s Not Just for Browsers Any More by simonw on Saturday March 06, 2010 @09:25AM (#1171562)
It depends on the promise library implementation - most will let you specify an "errback" (like a callback, but called if there is an error) and will trigger that if any of their children fail. Alternatively, some may let you specify a timeout and call your errback if that time elapses without all of the children finishing.
Re:JavaScript: It’s Not Just for Browsers Any More by Periodic on Tuesday March 09, 2010 @04:18PM (#1179411)
Looks like the formal name for what I was trying to do. Now I know what to google!