Create a gist now

Instantly share code, notes, and snippets.

@caike /promises.js
Last active Aug 29, 2015

What would you like to do?
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);
}
Owner

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