Skip to content

Instantly share code, notes, and snippets.

@caike
Last active August 29, 2015 14:21
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 caike/61a01b5a97117f16ffc6 to your computer and use it in GitHub Desktop.
Save caike/61a01b5a97117f16ffc6 to your computer and use it in GitHub Desktop.
Promises demo
console.log("A");
var returnFromTwo = stepOne().then(stepTwo);
console.log("B");
returnFromTwo.then(stepThree);
console.log("C");
function stepOne(){
console.log("running stepOne");
return new Promise(function(resolve, reject){
console.log("running stepOne Promise");
setTimeout(_ => resolve("resolved stepOne"), 1000);
});
}
function stepTwo(argToResolve){
console.log("running stepTwo with arg: ", argToResolve);
return new Promise(function(resolve, reject){
console.log("running stepTwo Promise");
setTimeout(_ => resolve("resolved stepTwo"), 5000);
});
}
function stepThree(argToResolve){
console.log("running stepThree ", argToResolve);
}
@caike
Copy link
Author

caike commented May 20, 2015

Output:

A
running stepOne
running stepOne Promise
B
C
running stepTwo with arg:  resolved stepOne
running stepTwo Promise
running stepThree  resolved stepTwo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment