Last active
December 22, 2015 21:09
-
-
Save dustingetz/6530998 to your computer and use it in GitHub Desktop.
promises are nothing more than async functions
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
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