Skip to content

Instantly share code, notes, and snippets.

@Daiz
Created May 18, 2013 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daiz/5604333 to your computer and use it in GitHub Desktop.
Save Daiz/5604333 to your computer and use it in GitHub Desktop.
require! \Q
# if you're not using prelude-ls
each = (fn, array) ->
[fn i for i in array]
random-msec = ->
Math.ceil Math.random! * 1000
delay = (n, v) ->
d = Q.defer!
set-timeout (-> d.resolve v), n
return d.promise
# list of promises constructed with a list comprehension
Q.all [delay random-msec!, i for i from 1 to 10]
.then (plist) -> console.log each (.value-of! * 2), plist # promise list
.fail (error) -> console.log error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment