Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save VladimirCores/8c67762d34715e27eb640517b976cbab to your computer and use it in GitHub Desktop.
Save VladimirCores/8c67762d34715e27eb640517b976cbab to your computer and use it in GitHub Desktop.
seqauncer
/*
* 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