dojo/promise/all not working with esri/request

3129
1
10-05-2015 11:23 AM
JasonLevine
Occasional Contributor II

This seems pretty straightforward, but I'm unable to get it to work.

I'd like to get the layer infos for selected layers in my map service using multiple esri/requests with a promise.  I have a visibleLayers array that I'm using to create each request:

<code>

var visibleLayers = [0,1];

var requestGroup = [];

array.forEach(visibleLayers, function(visibleLayer,i)

{

     var requestHandle = esriRequest(

     {

          url: dynamicLayer.url+"/"+visibleLayer,

          content: {f: "json"},

          callbackParamName: "callback"

     });

     requestGroup.push(requestHandle);

});

promises = all(requestGroup);

promises.then(processResults);

function processResults(results)

{

          //process results

}

</code>

Everything looks ok, but I never enter my processResults function.  I know that the return for esriRequest is deferred, so I'm not sure what's going wrong.

Any ideas?

Thanks,

Jason

0 Kudos
1 Reply
JasonLevine
Occasional Contributor II

Never mind.  For some reason, the following works:

var visibleLayers = [0,1];

var requestGroup = [];

array.forEach(visibleLayers, function(visibleLayer,i)

{

     var requestHandle = esriRequest(

     {

          url: dynamicLayer.url+"/"+visibleLayer,

          content: {f: "json"},

          callbackParamName: "callback"

     });

     requestGroup.push(requestHandle);

});

all(requestGroup).then(function(results)

{

          //process results

});

0 Kudos