public
Created

  • Download Gist
async-1-a.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14
 
var Q = require("events");
 
exports.and = function (a, b) {
return Q.when(a, function (a) {
return Q.when(b, function (b) {
return a && b;
});
});
};
 
Q.when(exports.and(true, true), function (and) {
print(and);
});
async-1-b.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 
var Q = require("events");
 
exports.and = function (a, b) {
return Q.when(a, function (a) {
return Q.when(b, function (b) {
return a && b;
});
});
};
 
var a = Q.defer();
var b = Q.defer();
 
Q.when(exports.and(a.promise, b.promise), function (and) {
print(and);
});
 
a.resolve(true);
b.resolve(false);
async-2-a.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 
var Q = require("events");
 
exports.and = function (a, b) {
return Q.when(a, function (a) {
return Q.when(b, function (b) {
return a && b;
});
});
};
 
exports.all = function (values) {
return values.reduce(function (a, b) {
return exports.and(a, b);
});
};
 
Q.when(exports.all([true, true, true]), function (and) {
print(and);
});
async-2-b.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 
var Q = require("events");
 
exports.and = function (a, b) {
return Q.when(a, function (a) {
return Q.when(b, function (b) {
return a && b;
});
});
};
 
exports.all = function (values) {
return values.reduce(function (a, b) {
return exports.and(a, b);
});
};
 
var deferred = Q.defer();
 
Q.when(exports.all([true, deferred.promise, true]), function (and) {
print(and);
});
 
deferred.resolve(false);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.