Created
December 23, 2014 00:47
-
-
Save bencooling/d912279015bbaefce292 to your computer and use it in GitHub Desktop.
Node Promises Bluebird
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
"use strict"; | |
var BbPromise = require('bluebird'); | |
function delay(ms) { | |
var deferred = BbPromise.pending(); | |
setTimeout(function(){ | |
deferred | |
.fulfill("Hello "+ ms); | |
}, ms); | |
return deferred.promise; | |
} | |
function plain(){ | |
return new BbPromise(function(resolve){ | |
resolve('foobah!'); | |
}); | |
} | |
BbPromise.settle([plain(), delay(2000), delay(4000)]) | |
.then(function(result){ | |
console.log(result[0].value()); | |
console.log(result[1].value()); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment