Created
July 15, 2017 17:00
-
-
Save skarfacegc/07cfc634cac7abc7b27bb89f42a5a3f5 to your computer and use it in GitHub Desktop.
Array promise chain created by skarfacegc - https://repl.it/JR1a/117
This file contains 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
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