Skip to content

Instantly share code, notes, and snippets.

@girvan
Created January 10, 2020 02:34
Show Gist options
  • Save girvan/b0db540d69b3edbf591b874045e521ff to your computer and use it in GitHub Desktop.
Save girvan/b0db540d69b3edbf591b874045e521ff to your computer and use it in GitHub Desktop.
run promise / task in sequence
var tasks = [
function(resolve) {
return setTimeout(function() {
console.log(1);
resolve();
}, 300);
},
function(resolve) {
return setTimeout(function() {
console.log(2);
resolve();
}, 200);
},
function(resolve) {
return setTimeout(function() {
console.log(3);
resolve();
}, 100);
},
];
tasks.reduce(function(promise, task) {
return promise.then(function() {
return new Promise(function(res) {
task(res);
});
});
}, Promise.resolve());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment