Last active
October 3, 2016 14:04
-
-
Save kyosuke/424ba07152aaeb3fe505f59dc9b0d6f5 to your computer and use it in GitHub Desktop.
直列Promise
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
console.log('start') | |
var array = [1,2,3]; | |
array.reduce((acc, current)=>{ | |
return acc.then(() => wait(current)) | |
}, Promise.resolve()) | |
function wait (x) { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
console.log(x) | |
resolve() | |
}, 1000) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment