Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.
/ promise-routine Public archive

Wrap a routine of Promise functions in Promise.all

License

Notifications You must be signed in to change notification settings

jamen/promise-routine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 on fn, where a sub-array is a list of arguments.
  • context (Anything): A context to bind to this on fn. (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
Jamen Marzonie

About

Wrap a routine of Promise functions in Promise.all

Resources

License

Stars

Watchers

Forks

Packages

No packages published