Select to view content in your preferred language

Promises replacement in arcgis version 4.27

423
1
07-19-2023 05:58 PM
samitalebi
New Contributor

I'm updating Arcgis SDK from 3 to 4.27 but don't have any idea how I can implement promises on the below code:

var identifyTask = new esri.tasks.IdentifyTask(FloodMapServerURL);
identifyTask.requestTimeout = 180;
var identifyParams = new esri.tasks.IdentifyParameters();
identifyParams.tolerance = 0;
identifyParams.returnGeometry = false;
//identifyParams.layerIds = [0, 2];
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.width = map.width;
identifyParams.height = map.height;
identifyParams.geometry = point;
identifyParams.mapExtent = map.extent;
var identifyDefer = identifyTask.execute(identifyParams);

map.infoWindow.show(screenPoint, map.getInfoWindowAnchor(screenPoint));
map.infoWindow.setTitle("Loading...");
map.infoWindow.setContent("");

var promises = new all([qLGADefer, identifyDefer]);
promises.always(function (results) {

//calling another IdentityTask and having promises on the below code

var identifyTask = new esri.tasks.IdentifyTask(FloodMapServerURL);
identifyTask.requestTimeout = 180;
var identifyParams = new esri.tasks.IdentifyParameters();
identifyParams.tolerance = parseInt(tolerance, 10);
identifyParams.returnGeometry = false;
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.width = map.width;
identifyParams.height = map.height;
identifyParams.geometry = point;
identifyParams.mapExtent = map.extent;
var identifyDefer = identifyTask.execute(identifyParams);

var promises = new all([identifyDefer]);
promises.always(function (results) {

//doing something
}

}); 

I used Identity instead of IdentifyTask in a new version but my main issue is how can I implement the promise or async/await model on the above code. 

0 Kudos
1 Reply
JoelBennett
MVP Regular Contributor

The 4.x API uses native Promises instead of dojo's Deferred objects.  To delay execution until multiple promises have resolved, you can use either Promise.all or Promise.allSettled, depending on which you find more suitable.