Created
May 18, 2013 13:01
-
-
Save Daiz/5604333 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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