Created
February 23, 2013 05:19
-
-
Save paulfryzel/5018573 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
var Q = require('q'); | |
function hello() { | |
var d = Q.defer(); | |
setTimeout(function() { | |
d.resolve('hello'); | |
}, 1000); | |
return d.promise; | |
} | |
function print(h) { | |
console.log(h + ', world'); | |
} | |
function one() { | |
var d = Q.defer(); | |
setTimeout(function() { | |
d.resolve(1); | |
}, 2000); | |
return d.promise; | |
} | |
function two() { | |
var d = Q.defer(); | |
setTimeout(function() { | |
d.resolve(2); | |
}, 1000); | |
return d.promise; | |
} | |
function sum(one, two) { | |
console.log(one + two); | |
} | |
Q.fcall(hello).done(print); | |
Q.allResolved([Q.fcall(one), Q.fcall(two)]).spread(sum).done(); | |
console.log('fooQ'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment