Skip to content

Instantly share code, notes, and snippets.

@black-black-cat
Created June 27, 2018 10:03
Show Gist options
  • Save black-black-cat/fb2d99df0aef281ccc370782c8f3e50a to your computer and use it in GitHub Desktop.
Save black-black-cat/fb2d99df0aef281ccc370782c8f3e50a to your computer and use it in GitHub Desktop.
sequenceTasks
// https://www.kancloud.cn/kancloud/promises-book/44249
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