javascript - Porting RSVP.js map idiom over to bluebird -
in rsvp.js, there elegant idiom:
var promises = [2, 3, 5, 7, 11, 13].map(function(id){ return getjson("/post/" + id + ".json"); }); rsvp.all(promises).then(function(posts) { // posts contains array of results given promises }).catch(function(reason){ // if of promises fails. });
however using library relies on, , exposes of bluebird's api. i'd rather avoid mixing in rsvp.js if may seem @ times more elegant.
what equivalent in bluebird, of rsvp.js code snippet above?
except using bluebird's promise
namespace instead of rsvp
, can stay same - using promise.all
. also, mixing promises conform promises a+ specification should work well, might not have change anything.
while don't much, bluebird has own idiom task - promise.map
:
promise.map([2, 3, 5, 7, 11, 13], function(id){ return getjson("/post/" + id + ".json"); }).then(function(posts) { // posts contains array of results given promises }).catch(function(reason){ // if of promises fails. });
Comments
Post a Comment