
The async nature of javascript is awesome at times and awful at times. For those awful times there are libraries to help ease the pain. Async.js is an great library that has all kinds of different flow control methods. The only problem is that it was complete overkill for 99% of the use cases that I had. On top of that, I wanted to use it in the browser and all those extra functions that I was never going to use would be wasted bytes that would be downloaded by the user. So... if an existing library doesn't fit your needs, write your own.
Resistance is a tiny (463 bytes, 298 bytes gzipped) library that gives you the two most used, at least for me, flow control functions: series and parallel.
Here's where to check it out:
Live Demo (JSBin) | Download (Dev) | Download (Prod) | Github
node: npm install resistance
//Test Function A
var testA = function(cb) {
setTimeout(function() {
console.log("Test A Complete");
cb();
}, 500);
};
//Test Function B
var testB = function(cb) {
setTimeout(function() {
console.log("Test B Complete");
cb();
}, 500);
};
R.series([
testA,
testA,
testA
], function() {
console.log("Series Complete");
});
R.parallel([
testB,
testB,
testB
], function() {
console.log("Parallel Complete");
});
When you run it, you'll see this in the console: