I had this exact problem and was surprised there aren't better answers in Node. We do a lot asynchronous data collecting and processing, and use Redis queues to handle the jobs. Often one action will trigger subsequent tasks that are added to the queue, and I need to know that my job is enqueued (an I/O operation to write to Redis) before I move on, disconnect from Redis, etc.
As others pointed out, you could just use the async<https://github.com/caolan/async>library or promises, but that will sacrifice the nice decoupling you get with a event emitters and listeners (and one of the best parts of JavaScript). The better solution is to keep emitting events, but have the listeners just turn around and add the real work to an async queue<https://github.com/caolan/async#queue>. Then you can separately listen to this queue to know when all work is completed. Hope that helps, Ben On Saturday, October 5, 2013 12:48:42 PM UTC-7, David Herron wrote: > > While planning a new feature for my project (AkashaCMS) I realized that > EventEmitter's aren't the correct tool for one of the things I'm doing. > Are there alternatives to EventEmitter that fits the scenario I have. ... > a quick look through the NPM repository says there are some relavent > modules ... > > The issue is that I want to a) have my application proceed only when all > the event handlers finish running b) in some cases I need the event handler > to send a value > > EventEmitter.emit doesn't support a callback that's triggered when all > event handler invocations have finished. > > What that means is, for example, an array of functions to call each with a > known signature that includes a callback function. Then to use, for > example, async.eachSeries to invoke each in series... > > Here's a few relavent modules that look likely: > > https://npmjs.org/package/async-emit > https://npmjs.org/package/emit-and-callback > > http://underscorejs.org/ ?? > > > -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: 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 post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- 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]. For more options, visit https://groups.google.com/d/optout.
