Skip to content

Instantly share code, notes, and snippets.

@johan--
Forked from chrisabrams/sample.js
Created October 14, 2016 13:05
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 johan--/974a65c0672d97c5606626ef46037c94 to your computer and use it in GitHub Desktop.
Save johan--/974a65c0672d97c5606626ef46037c94 to your computer and use it in GitHub Desktop.
Bluebird promise chain example
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