Skip to content

Instantly share code, notes, and snippets.

@dksheffield
Created April 14, 2016 13:13
Show Gist options
  • Save dksheffield/525a1a89c3b507bb53d036be9476f186 to your computer and use it in GitHub Desktop.
Save dksheffield/525a1a89c3b507bb53d036be9476f186 to your computer and use it in GitHub Desktop.
console.log('Loading function');
var Promise = require('promise');
doPromiseOne()
.then(doPromiseTwo)
.then(doPromiseThree);
function doPromiseOne() {
return promiseOne().then(function(data) {
console.log(data);
});
}
function doPromiseTwo() {
return promiseTwo().then(function(data) {
console.log(data);
});
}
function doPromiseThree() {
return promiseThree().then(function(data) {
console.log(data);
});
}
function failPromise(msg) {
throw new Error(msg);
}
function promiseOne() {
console.log("starting promise one");
return new Promise(function (fulfill, reject){
setTimeout(function () {
console.log("promise one success");
fulfill("promise one success");
}, 2000)
});
}
function promiseTwo() {
console.log("starting promise two");
return new Promise(function (fulfill, reject){
setTimeout(function () {
console.log("promise two success");
fulfill("promise two success");
}, 2000)
});
}
function promiseThree() {
console.log("starting promise three");
return new Promise(function (fulfill, reject){
setTimeout(function () {
console.log("promise three success");
fulfill("promise three success");
}, 2000)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment