Created
February 10, 2017 03:59
-
-
Save gluons/eb48ead19f756cbe704928edc48d6793 to your computer and use it in GitHub Desktop.
Bluebird Promise Sequential
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
/* | |
* Sequential Promises | |
* Adapt from https://github.com/petkaantonov/bluebird/issues/70#issuecomment-32256273 | |
*/ | |
function promiseSequential(tasks) { | |
return Promise.reduce(tasks, function (values, task) { | |
if (typeof task === 'function') { | |
return task().then(function (value) { | |
values.push(value); | |
return values; | |
}); | |
} else if (task instanceof Promise) { | |
return task.then(function (value) { | |
values.push(value); | |
return values; | |
}); | |
} else { | |
values.push(task); | |
return values; | |
} | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment