Created
July 21, 2017 11:48
-
-
Save max-lt/0cd7133b31105871f71b403314a27af5 to your computer and use it in GitHub Desktop.
Promise chain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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