0

I am trying to figure out what data-structure of promises I can use in $q.all() function. I know that I can give it an array of promises and a map of promises, but can I give it an aribitrary depth map as well? eg can I do something like:

var map = {};
map["A"] = {};
map["A"]["B"] = MyService.getPromise();

$q.all(map).then(function(resultMap){
    // does resultMap match the structure of the input map?
    console.debug(resultMap["A"]["B"])
})

And if I can't, what is the suggested way to do something like this? I would like to know the original level inside the map of my resulting data.

rex
  • 3,133
  • 6
  • 35
  • 62

1 Answers1

0

For me this looks pretty simple and works:

 var promises = [];

 promises.push(MyService.getPromise().then(function(result) {
    map["A"]["B"] = result;
 }));

 promises.push(MyService.getPromise().then(function(result) {
    map["A"]["C"] = result;
 }));

...

$q.all(promises).then(function() {
  // map is initialized here
})
Petr Averyanov
  • 9,327
  • 3
  • 20
  • 38