Skip to content

Instantly share code, notes, and snippets.

@tomysmile
Forked from chrisabrams/sample.js
Created February 9, 2017 02:58
Show Gist options
  • Save tomysmile/fcaada425487ac9dea3b607d5db66025 to your computer and use it in GitHub Desktop.
Save tomysmile/fcaada425487ac9dea3b607d5db66025 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