Skip to content

Instantly share code, notes, and snippets.

@paulfryzel
Created February 23, 2013 05:19
Show Gist options
  • Save paulfryzel/5018573 to your computer and use it in GitHub Desktop.
Save paulfryzel/5018573 to your computer and use it in GitHub Desktop.
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