Created
October 2, 2020 12:47
-
-
Save nsacerdote/0864b1bacac15f95fdd038cdb7159dc0 to your computer and use it in GitHub Desktop.
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
function allSequential(promiseFns) { | |
const initPromise = Promise.resolve([]); | |
return promiseFns.reduce(_chainPromise, initPromise); | |
function _chainPromise(acc, pFn) { | |
return acc.then(result => pFn().then(pResult => [...result, pResult])); | |
} | |
} | |
allSequential([ | |
() => task1(), | |
() => task2(), | |
() => task3() | |
]).then(...) // then and catch behaves as Promise.all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment