Created
July 12, 2014 15:08
-
-
Save azu/05f5a328a5c70d131ec9 to your computer and use it in GitHub Desktop.
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
# 実行すると1秒後に実行回数をprintするPromise化された関数 | |
cnt = 0 | |
f = -> new Promise (done) -> | |
setTimeout (-> | |
console.log 'done', cnt++ | |
done() | |
), 1000 | |
# fを直列に4回実行する | |
promises = [f, f, f, f] | |
seq = promises.reduce ((ret, p) -> | |
ret.then p | |
), Promise.resolve() | |
seq.then => console.log 'finish' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment