Skip to content

Instantly share code, notes, and snippets.

@chinmay185
Created April 27, 2015 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chinmay185/30d6b7d70868f99d610b to your computer and use it in GitHub Desktop.
Save chinmay185/30d6b7d70868f99d610b to your computer and use it in GitHub Desktop.
using map to start multiple async operations at the same time
var Promise = require("bluebird");
var productIds = ["productId1", "productId2", "productId3"];
var getProductsFromDb = function(productId) {
// returns a promise of product
}
var productPromises = productIds.map(getProductFromDb);
Promise.all(productPromises).then(function(products) {
// calculate total price here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment