promise-routine
v2.0.0
Published
Wrap a routine of Promise functions in Promise.all
Downloads
5
Readme
promise-routine
Wrap a routine of Promise functions in Promise.all
Repeat a Promise
-returning function with different arguments and wrap the results in Promise.all
.
const routine = require('promise-routine');
const glob = require('glob');
routine(glob, ['foo/**.js', 'baz/**.css'])
.then(globs => {
// ...
});
Installation
$ npm install --save promise-routine
Usage
const routine = require('routine');
const promiseFunction = require('...');
routine(promiseFunction, [...])
.then(results => {
});
On object methods (or context-sensitive functions), rebind context this
with a third argument:
routine(lib.foo, [...], lib)
.then(results => {
});
API
routine(fn, sets, [context])
fn
(Function): Function for the routine to use.sets
(Array): A list of arguments to apply onfn
, where a sub-array is a list of arguments.context
(Anything): A context to bind tothis
onfn
. (Default:fn
)
What is the format of sets
?: Sets is a 2 dimensional array, where the second level is a list of arguments:
// This:
routine(func, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
// is equivalent to:
Promise.all([
func(1, 2, 3),
func(4, 5, 6),
func(7, 8, 9)
]);
You can also supply non-array sets to supply one argument:
// This:
routine(func, [1, 2, 3]);
// is equivalent to:
Promise.all([
func(1),
func(2),
func(3)
]);
Returns: Promise
Credits
| | |:---:| | Jamen Marzonie |