Skip to content

Instantly share code, notes, and snippets.

@skarfacegc
Created July 15, 2017 17:00
Show Gist options
  • Save skarfacegc/07cfc634cac7abc7b27bb89f42a5a3f5 to your computer and use it in GitHub Desktop.
Save skarfacegc/07cfc634cac7abc7b27bb89f42a5a3f5 to your computer and use it in GitHub Desktop.
Array promise chain created by skarfacegc - https://repl.it/JR1a/117
let foo = [];
foo[0] = () => {
return new Promise((resolve,reject) => {
setTimeout(() =>{
console.log('a');
resolve(1);
}, 100);
});
}
foo[1] = () => {
return new Promise((resolve,reject) => {
setTimeout(() =>{
console.log('b');
resolve(2);
}, 100);
});
}
foo[2] = () => {
return new Promise((resolve,reject) => {
setTimeout(() =>{
console.log('c');
resolve(3);
}, 1);
});
}
foo[3] = () => {
return new Promise((resolve,reject) => {
setTimeout(() =>{
console.log('d');
resolve(4);
}, 1);
});
}
foo.reduce((promise, cur) =>{
return promise
.then(cur)
.then(val =>{
console.log(val +"\n");
});
},Promise.resolve()).then(()=>{console.log('all done')});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment