Skip to content

Instantly share code, notes, and snippets.

@azu
Created July 12, 2014 15:08
Show Gist options
  • Save azu/05f5a328a5c70d131ec9 to your computer and use it in GitHub Desktop.
Save azu/05f5a328a5c70d131ec9 to your computer and use it in GitHub Desktop.
# 実行すると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