Last active
August 29, 2015 14:08
-
-
Save joepie91/899205c6dffbbd6ee3f4 to your computer and use it in GitHub Desktop.
Promises
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
/* Without Promises */ | |
asynchronousFunctionOne(function(value){ | |
somethingSync(value); | |
asynchronousFunctionTwo(function(){ | |
somethingElseSync(); | |
asynchronousFunctionThree(function(){ | |
console.log("Done!"); | |
}); | |
}); | |
}); | |
/* With Promises */ | |
Promise.try(function(){ | |
return asynchronousFunctionOne(); | |
}).then(function(value){ | |
somethingSync(value); | |
return asynchronousFunctionTwo(); | |
}).then(function(){ | |
somethingElseSync(); | |
return asynchronousFunctionThree(); | |
}).then(function(){ | |
console.log("Done!"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment