Skip to content

Instantly share code, notes, and snippets.

@aSapien
Last active December 3, 2022 13:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aSapien/aeae5301d573408854d2a4d2394a8a9c to your computer and use it in GitHub Desktop.
Save aSapien/aeae5301d573408854d2a4d2394a8a9c 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