-
-
Save cicorias/0c07dc20c744e9e54016a2fbba46b5f1 to your computer and use it in GitHub Desktop.
Bluebird promise chain example
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
Promise = require('bluebird') | |
var A = function() { | |
return new Promise(function(resolve, reject) { | |
var result = 'A is done' | |
console.log(result) | |
resolve(result); | |
}) | |
} | |
var B = function() { | |
return new Promise(function(resolve, reject) { | |
var result = 'B is done' | |
setTimeout(function() { | |
console.log(result) | |
resolve(result); | |
}, 2000) | |
}) | |
} | |
var C = function() { | |
return new Promise(function(resolve, reject) { | |
var result = 'C is done' | |
console.log(result) | |
resolve(result); | |
}) | |
} | |
var D = function() { | |
return new Promise(function(resolve, reject) { | |
var result = 'D is done' | |
console.log(result) | |
resolve(result); | |
}) | |
} | |
A() | |
.then(function(result) { | |
return B(); | |
}) | |
.then(C) | |
.then(D) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment