Created
May 1, 2013 11:27
-
-
Save slightlyoff/5494810 to your computer and use it in GitHub Desktop.
Error-first callback style Futures.
This file contains 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
var log = console.log.bind(console); | |
// Like .then(), except we move to a single callback | |
asyncAPI().when(function(err, value) { | |
if (err) { | |
// error handling/recovery | |
// ... | |
// If return is instanceof Error, continues error chain | |
return new Error(err.toString()); | |
} | |
return "success!"; | |
}).when(log); | |
// Like .done(), except single callback | |
asyncAPI().finished(log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment