Created
April 27, 2015 15:46
-
-
Save chinmay185/30d6b7d70868f99d610b to your computer and use it in GitHub Desktop.
using map to start multiple async operations at the same time
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
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