Skip to content

Instantly share code, notes, and snippets.

@akras14
Created March 14, 2014 19:51
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 akras14/9555442 to your computer and use it in GitHub Desktop.
Save akras14/9555442 to your computer and use it in GitHub Desktop.
var Q = require('q');
var FS = require('fs');
var test = function(){
var deferred = Q.defer();
FS.readFile("foo.txt", "utf-8", function (error, text) {
if (error) {
deferred.reject(25);
} else {
deferred.resolve(text);
}
});
return deferred.promise;
}
test()
.then(function(){
console.log("Success");
})
.fail(function(errorCode){
console.log("Fail");
console.log(errorCode);
if (errorCode === 25) {
console.log("We are good");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment