Skip to content

Instantly share code, notes, and snippets.

@himn1
Created November 26, 2015 23:33
Show Gist options
  • Save himn1/f2039979423bd45921ed to your computer and use it in GitHub Desktop.
Save himn1/f2039979423bd45921ed to your computer and use it in GitHub Desktop.
JS/CoffeeScript Promises
dict = {a: 1, b: 2, c: 3, d: 4, e: 5}
pro = Promise.resolve()
for k, v of dict
func = (k) ->
pro = pro.then ->
return new Promise (res, rej) ->
if dict[k] is 4
rej 'fourrrr!!!!'
return
console.log dict[k]
res()
func k
pro.catch (e) -> console.log "error: #{e}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment