waitgroup

waitgroup.js - concurrency synchronization primitive ============ This is a translation of Go's sync.WaitGroup for JavaScript, used extensively in TextDrop.

waitgroup.js - concurrency synchronization primitive

This is a translation of Go's sync.WaitGroup for JavaScript, used extensively in TextDrop.

Use this if you want run several asynchronous tasks concurrently and run a function when all the results come back. (E.g. if you want to make multiple web requests or database queries, then use them together).

This is much better than making each request in serial, and takes advantage of JavaScript's asynchronous design to boost the response time of your program by making your requests concurrent.

var wg = new WaitGroup;
 
wg.add();
initResource1().on("done", function(){
  wg.done();
});
 
wg.add();
initResource2().on("done", function(){
  wg.done();
});
 
wg.add();
initResource3().on("done", function(){
  wg.done();
});
 
wg.wait(function(){
  console.log("All done!")
});

Increments the WaitGroup counter

Decrements the WaitGroup counter. When the counter becomes 0, the function passed to wait() will be called.

Registers a callback to be called when all tasks in the WaitGroup are done.

Run the tests with npm test