Skip to content

Instantly share code, notes, and snippets.

@joepie91
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joepie91/899205c6dffbbd6ee3f4 to your computer and use it in GitHub Desktop.
Save joepie91/899205c6dffbbd6ee3f4 to your computer and use it in GitHub Desktop.
Promises
/* 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