A simple utility for dealing with parallel async code
A simple module for parallel execution with a shared complete callback.
You can use it basically any time you have more than one events that need to happen before you take action, where it is not important which event happens first.
Note: It should work in the browser as well, but hasn't been packaged yet for easy usage, nor has it been tested very thoroughly.
npm install waitforit
Start two async calls that can run in parallel:
var waitforit = ;var wait =;var first = ;;var second = ;;
Have the callbacks return results:
var wait =;var first = ;;var second = ;;
Sometimes you might not have generated all the async handlers right away, or you want to have the handlers called multiple times (with the last result overriding the previous) you can control whether or not you're done by returning a boolean for whether or not it's done in the complete callback.
var wait =;
In many cases you can just pass the async handlers straight into async calls, eg. with reading files, you can do something like:
var fs =waitforit = ;var wait =;fs;fs;
Note that the final callback will be called immediately if any of the async handlers get passed an error.