Skip to content

Instantly share code, notes, and snippets.

@thebigredgeek
Created August 1, 2016 16:45
Show Gist options
  • Save thebigredgeek/42877d96726fc6be269faf08d70a43f6 to your computer and use it in GitHub Desktop.
Save thebigredgeek/42877d96726fc6be269faf08d70a43f6 to your computer and use it in GitHub Desktop.
using promises with bluebird
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