Created
June 27, 2018 10:03
-
-
Save black-black-cat/fb2d99df0aef281ccc370782c8f3e50a to your computer and use it in GitHub Desktop.
sequenceTasks
This file contains hidden or 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
// 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