Skip to content

Instantly share code, notes, and snippets.

@joepie91
Created April 15, 2015 23:22
Show Gist options
  • Save joepie91/2aafe9e4830e0d0c8171 to your computer and use it in GitHub Desktop.
Save joepie91/2aafe9e4830e0d0c8171 to your computer and use it in GitHub Desktop.
Nested mapping in bluebird
var Promise = require("bluebird");
Promise.try(function(){
return getItemsSomehow()
}).map(function(topLevelItem){
return Promise.try(function(){
return doAsyncThingWith(topLevelItem);
}).map(function(childItem){
return doOtherAsyncThingWithEach(childItem);
});
}).then(function(finalResult){
/* finalResult will contain an array of arrays, all of it asynchronously resolved. */
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment