Skip to content

Instantly share code, notes, and snippets.

@yesil
Created December 14, 2017 22:24
Show Gist options
  • Save yesil/adce6da7de0ff9c86fabb0cdb684a670 to your computer and use it in GitHub Desktop.
Save yesil/adce6da7de0ff9c86fabb0cdb684a670 to your computer and use it in GitHub Desktop.
Promises in serial
const tasks = getTaskArray();
return tasks.reduce((promiseChain, currentTask) => {
return promiseChain.then(chainResults =>
currentTask.then(currentResult =>
[ ...chainResults, currentResult ]
)
);
}, Promise.resolve([])).then(arrayOfResults => {
// Do something with all results
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment