Created
April 4, 2018 04:55
-
-
Save TianyiLi/428624705faee9341b47c00224a24873 to your computer and use it in GitHub Desktop.
Promise sequence
This file contains 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
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