Skip to content

Instantly share code, notes, and snippets.

@nsacerdote
Created October 2, 2020 12:47
Show Gist options
  • Save nsacerdote/0864b1bacac15f95fdd038cdb7159dc0 to your computer and use it in GitHub Desktop.
Save nsacerdote/0864b1bacac15f95fdd038cdb7159dc0 to your computer and use it in GitHub Desktop.
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