Skip to content

Instantly share code, notes, and snippets.

@kriskowal
Created February 3, 2010 05:29
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 kriskowal/293354 to your computer and use it in GitHub Desktop.
Save kriskowal/293354 to your computer and use it in GitHub Desktop.
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);
});
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);
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);
});
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment