Created
March 4, 2020 21:36
-
-
Save VladimirCores/8c67762d34715e27eb640517b976cbab to your computer and use it in GitHub Desktop.
seqauncer
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
/* | |
* serial executes Promises sequentially. | |
* @param {funcs} An array of funcs that return promises. | |
* @example | |
* const urls = ['/url1', '/url2', '/url3'] | |
* serial(urls.map(url => () => $.ajax(url))) | |
* .then(console.log.bind(console)) | |
*/ | |
export const sequence = funcs => funcs.reduce((acc, b) => acc.then((f => x => f().then((list => Array.prototype.concat.bind(list))(x)))(b)), Promise.resolve([])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment