promise-circuit

0.2.0 • Public • Published

promise-circuit

Create a circuit-type flow for Promise functions.

Create a series of Promise-returning functions (with prepared arguments):

const foo = new Circuit();
 
for (let item of something) {
  foo.add(myFn, [item, -item]);
}
 
foo.run().then(results => {
  // ...
});

Installation

$ npm install --save promise-circuit

Usage

import Circuit from 'promise-circuit';

new Circuit([series])

Create a circuit.

  • series (Array): Pre-provided series.

Series format:

new Circuit([[fn, args], [fn, args]]);

Circuit#add(fn, [args])

Add a promise function to the circuit.

  • fn (function): A promse-returning (or thenable) function.
  • args (Array): Arguments to be passed in once the circuit is ran.

Circuit#run()

Run the series of promise functions in a circuit-like flow.

Returns Promise with all the results of the circuit.

Credits

jamen
Jamen Marzonie

Readme

Keywords

none

Package Sidebar

Install

npm i promise-circuit

Weekly Downloads

0

Version

0.2.0

License

none

Last publish

Collaborators

  • jamen