Skip to content

Instantly share code, notes, and snippets.

@gluons
Created February 10, 2017 03:59
Show Gist options
  • Save gluons/eb48ead19f756cbe704928edc48d6793 to your computer and use it in GitHub Desktop.
Save gluons/eb48ead19f756cbe704928edc48d6793 to your computer and use it in GitHub Desktop.
Bluebird Promise Sequential
/*
* 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