laters
v0.0.3
Published
Async scatter/gather and pipeline
Downloads
47
Readme
laters
A really simple (but useful?) utility lib for async scatter/gather (both ordered, and keyed) and pipelines.
Ripped from the guts of Anvil.
Pardon the silly examples, imagine that the async calls are doing something super important :)
Parallel - async map with preserved results
laters.parallel( [ 1, 2, 3], function( x, done ) { done( x + 1 ); }, console.log );
// results in [ 2, 3, 4 ]
Execute a hash of asynchronous functions and store results in keys
var hash = {
a: function( done ) { done( 1 ); },
b: function( done ) { done( 2 ); },
c: function( done ) { done( 3 ); }
};
laters.mapped( hash, console.log );
// results in { a: 1, b: 2, c: 3 }
Pipeline - asynchronously execute a pipeline
var actions = [
function( x, done ) { done( x + 5 ); },
function( x, done ) { done( x / 2 ); },
function( x, done ) { done( x * 4 ); },
];
laters.pipeline( 5, actions, console.log );
// results in 20 ( 5 + 5 == 10 / 2 == 5 * 4 == 20 )
License
MIT License - http://opensource.org/licenses/MIT