Created
September 10, 2015 09:49
-
-
Save hacke2/645f7f0061e7bd147bd7 to your computer and use it in GitHub Desktop.
promise sequence exec tasks
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