Created
November 6, 2015 14:15
-
-
Save Loupax/67d09d1aeb69c876cf43 to your computer and use it in GitHub Desktop.
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
| /** | |
| * Runs an array of promises one after another instead of in parallel | |
| * | |
| * @param array | |
| * @param callback | |
| * | |
| * @returns {*} | |
| */ | |
| function sequential(array, callback) { | |
| var result = []; | |
| return Q(array.reduce(function (previousPromise, item) { | |
| return previousPromise.then(function () { | |
| return callback(item); | |
| }).then(function (res) { | |
| result.push(res); | |
| return res; | |
| }); | |
| }, Q([]))).then(function () { | |
| return result; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment