Skip to content

Instantly share code, notes, and snippets.

@eduardonunesp
Created March 25, 2015 12:48
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 eduardonunesp/acfd6f8d377723a15fdc to your computer and use it in GitHub Desktop.
Save eduardonunesp/acfd6f8d377723a15fdc to your computer and use it in GitHub Desktop.
Accept the first fulfilled value
var Q = require('q');
var f = function(a) {
var defer = Q.defer();
if (a % 2 === 0)
defer.resolve(a);
else
defer.reject(new Error("Rejected, module is odd" + a));
return defer.promise;
};
var p = Q.any([f(42), f(12)])
.then(function(result) {
console.log(result);
})
.catch(function(err) {
console.error("Error " + err.message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment