Skip to content

Instantly share code, notes, and snippets.

@TianyiLi
Created April 4, 2018 04:55
Show Gist options
  • Save TianyiLi/428624705faee9341b47c00224a24873 to your computer and use it in GitHub Desktop.
Save TianyiLi/428624705faee9341b47c00224a24873 to your computer and use it in GitHub Desktop.
Promise sequence
function sequenceTasks(tasks) {
function recordValue(results, value) {
results.push(value);
return results;
}
var pushValue = recordValue.bind(null, []);
return tasks.reduce(function (promise, task) {
return promise.then(task).then(pushValue);
}, Promise.resolve());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment