Skip to content

Instantly share code, notes, and snippets.

@dustingetz
Last active December 22, 2015 21:09
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 dustingetz/6530998 to your computer and use it in GitHub Desktop.
Save dustingetz/6530998 to your computer and use it in GitHub Desktop.
promises are nothing more than async functions
function onSuccess(val) { ... }
function onError(err) { ... }
try {
onSuccess(g(f(42))); // function composition
}
catch(e) {
onError(e)
}
Q.delay(42, 1000).then(f).then(g).then(onSuccess, onError);
// Promises let you compose async functions. Nothing more, nothing less.
// promise library: https://github.com/kriskowal/q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment