<jga.me/>

resistance

Want to play around and see a live demo of resistance? Check this out on jsbin: http://jsbin.com/uboquz/4/edit.

In case you missed my post on my javascript async flow control library, go here.

Leave a comment

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

Here's what it looks like:

//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:

  • Test A Complete - 1st call from series (500 ms)
  • Test B Complete - 1st call from parallel (500 ms)
  • Test B Complete - 2nd call from parallel (500 ms)
  • Test B Complete - 2nd call from parallel (500 ms)
  • Parallel Complete - All of parallel functions have finished (500 ms)
  • Test A Complete - 2nd call from series (1000 ms)
  • Test A Complete - 3rd call from series (1500 ms)
  • Series Complete - All of series functions have finished (1500 ms)
Leave a comment

Categories

Recent Posts