AnsweredAssumed Answered

Promises and async/await for esriRequests();

Question asked by Mtgeo79 on Feb 18, 2020
Latest reply on Feb 18, 2020 by taungesriaustralia-com-au-esridist

I have some code which has several nested fetch api promises as such:

require({"esri/request}"], function(esriRequest){

   var options ={

      //some options


var url = 'SomeParcelGeometryRestService'

esriRequest(url, options).then(


   var LLDOptions ={

         //more options 

         //takes geometry of 'response' from Parcel geometry request to run an intersect on the LegalLandDesc RS url


   esriRequest('aLegal Land Desc RS url', newOptions).then(



   var StipOptions={

         //takes the geometry from the first Parcel geo request for intersect with Stip url


   esriRequest('Stipulations Rest Service Url', StipOptions).then(


      //write a pdf report using jsPDF after going to an AJAX call to a SQL esri db. and returning results from the objects resovled in the LLD request and the Stip Request which I am currently still embedded in




The issue here is that the Stipulation Intersect Request is on the same level as the LLD Intersect Request, and both use the geometry from the first Parcel EsriRequest. So they are both embedded in that Parcel Geo Get Request, but not embedded within each other, and yet I am using an array or an object (either way) from the LLD request in the Stip request and need to wait till it is not, but it really does not work to embed it in the LLD response. 

My thoughts are I could chain them , or use an async/await method to tell StipRequest to wait on the LLD request.

Anyone know how to do this? Do I need to put the Stip request in a seperate function and call that function with .then after LLD request?