Created
August 30, 2012 21:52
-
-
Save rektide/3542173 to your computer and use it in GitHub Desktop.
Chainable error-resulting functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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