Skip to content

Instantly share code, notes, and snippets.

@rektide
Created August 30, 2012 21:52
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 rektide/3542173 to your computer and use it in GitHub Desktop.
Save rektide/3542173 to your computer and use it in GitHub Desktop.
Chainable error-resulting functions
// option 1: use Q.when/Q.fcall along with a normal error throw
function doWork(){
throw "bad"
}
Q.when(doWork(),next)
Q.fcall(doWork()).then(next)
// option 2: craft a rejected promise & return that
function badPromise(err){
// note: reject(err) returns the now-rejected promise, not the defer.
return Q.defer().reject(err)
}
function doWork(){
return badPromise("bad")
}
doWork().then(next)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment