promise-circuit

Create a circuit-type flow for Promise functions.

Usage no npm install needed!

<script type="module">
  import promiseCircuit from 'https://cdn.skypack.dev/promise-circuit';
</script>

README

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