Skip to content

Instantly share code, notes, and snippets.

@okovalov
Forked from chrisabrams/sample.js
Created September 9, 2016 17:39
Show Gist options
  • Save okovalov/4f9539ac06b2ba058a008235102af194 to your computer and use it in GitHub Desktop.
Save okovalov/4f9539ac06b2ba058a008235102af194 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