Skip to content

Instantly share code, notes, and snippets.

@max-lt
Created July 21, 2017 11:48
Show Gist options
  • Save max-lt/0cd7133b31105871f71b403314a27af5 to your computer and use it in GitHub Desktop.
Save max-lt/0cd7133b31105871f71b403314a27af5 to your computer and use it in GitHub Desktop.
Promise chain
/**
* @description exec "fun" with each "arr" element, one after the other
* @template T, S
* @param {Array.<T>} arr
* @param {function(T): S} fun
* @returns Promise.<S>
*/
const promiseChain = (arr, fun) => arr.reduce((p, e) => p.then(() => fun(e)), Promise.resolve());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment