Skip to content

Instantly share code, notes, and snippets.

@slightlyoff
Created May 1, 2013 11:27
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 slightlyoff/5494810 to your computer and use it in GitHub Desktop.
Save slightlyoff/5494810 to your computer and use it in GitHub Desktop.
Error-first callback style Futures.
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