give-me
How it works
Give-me takes care of executing deferred functions in parallel/sequence, and allows you to use your functions exactly as they are keeping the well-known callback style. The only convention is that the callback arguments need to be the last in every function. The callback object is an array of callback results.
Installation
npm install give-me
all(functions [, arguments] [, maxConcurrency], callback)
Runs an array of functions in parallel, and returns (with a callback) an array of callbacks in the same order when all the functions had been called.
var giveMe = ; var { ; };var { ; }; giveMealla b { console; // will display [['a'],['b']]};
If functions need some parameters to work, they can be included in the optional "arguments" parameter. Just keep the callbacks in the end.
var giveMe = ; var { ; }; var { ; }; giveMealla b 'hello' 'world' 'hi' { console; // will display [['hello world'],['hello', 'hi']]};
When tuple argument provided it tries to return 2 arrays of results. In case the first array (supposed to be the errors) is an array of empty values it is nullified (so that callback is a function(x, y) => null, array).
var giveMe = ; var { ; }; var { ; }; giveMeallerrorFunc successFunc { console; // will display ['error', null] console; // will display [null, 'hello'];}; giveMeallsuccessFunc successFunc { console; // will display null console; // will display ['hello', 'hello'];};
any(functions [, arguments] [, conditionalFunction], callback)
Runs an array of functions in parallel, but returns (with a callback) just the fastest, ignoring all the other callbacks.
var giveMe = ; var { ; };var { ; }; giveMe;
Using the optional 'conditionalFunction' parameter the callback will be called when the fastest callback will satisfy a requirement provided through a sync function (in the example above, the 'c' function is the fastest that satisfies the condition, the callback for function b is anyway appended as processed before but it does not satisfies the requirement).
var giveMe = ; var { ; }var { ; }var { ; } giveMe;
sequence(functions [, arguments], callback)
Runs an array of functions in sequence, and returns (with a callback) an array of callbacks in the same order when all the functions had been called.
var giveMe = ; var { ; };var { ; }; giveMe;
License
MIT