Skip to content

Instantly share code, notes, and snippets.

@ali-master
Forked from aSapien/parseq.js
Created December 3, 2022 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ali-master/883ccedfcf0e1abe1448713dac413379 to your computer and use it in GitHub Desktop.
Save ali-master/883ccedfcf0e1abe1448713dac413379 to your computer and use it in GitHub Desktop.
Parallel / Sequential execution control flow with Promises in JS #javascript
export const parallel = (...fs) => sequential(
() => fs.map(f => f()),
Promise.all.bind(Promise));
export const sequential = (f, ...fs) => val => Promise.resolve()
.then(() => f(val))
.then(fs.length ? sequential(...fs) : id => id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment