Created
August 1, 2016 16:45
-
-
Save thebigredgeek/42877d96726fc6be269faf08d70a43f6 to your computer and use it in GitHub Desktop.
using promises with bluebird
This file contains hidden or 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
var Promise = require('bluebird'); | |
Promise.promisifyAll(City); // creates copies of every function with "Async" suffix... each return a promise | |
Promise.promisifyAll(Category); | |
Promise.all([ | |
City.getAsync(0), | |
Category.getAsync(0) | |
]).then(function (responses) { | |
var cityResponse = responses[0]; | |
var categoryResponse = responses[1]; | |
//do stuff with your city and category... aka res.render | |
}, function (errors) { | |
var cityGetError = errors[0]; | |
var categoryGetError = errors[1]; | |
//handle errors... aka res.status(500).send({error: 'something is broken!'}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment