-
-
Save johan--/974a65c0672d97c5606626ef46037c94 to your computer and use it in GitHub Desktop.
Bluebird promise chain example
This file contains 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