!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require,exports):"function"==typeof define&&define.amd&&define(["require","exports","tslib","../../deps/bluebird_fork","./ArcGisApiVersion","../../Validation","./tools","./MapProvider","../../Hooks","esri/request","esri/tasks/Geoprocessor","../../Task"],e)}(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var l=e("tslib"),c=l.__importDefault(e("../../deps/bluebird_fork")),o=e("./ArcGisApiVersion"),d=e("../../Validation"),f=e("./tools"),s=e("./MapProvider"),r=e("../../Hooks"),a=l.__importDefault(e("esri/request")),p=l.__importDefault(e("esri/tasks/Geoprocessor")),b=e("../../Task");function v(e,t){var o,s=void 0;if(null!=e){for(var r in e)o=r,Object.prototype.hasOwnProperty.call(e,o)&&((s=void 0===s?{}:s)[r]=t(e[r],r));return s}}i.prototype.execute=function(r,a,u){return l.__awaiter(this,void 0,void 0,function(){var i,n,t,o,s=this;return l.__generator(this,function(e){switch(e.label){case 0:return o=d.validation.string("url",r.url,d.validation.never),(i=new p.default(o)).outSpatialReference=u.getOutSR(r.outSpatialReference),i.processSpatialReference=u.getOutSR(r.processSpatialReference),t=d.validation.exists("arguments",r.arguments,{}),n=f.isAbortable(a.cancellationToken)?{signal:a.cancellationToken.signal}:void 0,o=i.submitJob(t,n),t=o,this.needToWaitForJobCompletion()?[4,o]:[3,2];case 1:o=e.sent(),t=i.waitForJobCompletion(o.jobId,n),e.label=2;case 2:return f.schedulePromiseCancellation(a,t),[2,f.inline(t,function(r){return l.__awaiter(s,void 0,void 0,function(){var o,t,s;return l.__generator(this,function(e){switch(e.label){case 0:return"job-succeeded"!==r.jobStatus&&"esriJobSucceeded"!==r.jobStatus?[3,3]:r.results?[3,2]:[4,this.populateResults(i.url,r,n)];case 1:e.sent(),e.label=2;case 2:return o=[],t=v(r.results,function(e,t){t=c.default.resolve(i.getResultData(r.jobId,t,n));return f.schedulePromiseCancellation(a,t),o.push(t),t}),s=c.default.all(o),b.Task.race([s,a.cancellationToken]).finally(function(){s.isPending()&&i.cancelJob(r.jobId)}),[2,f.inline(s,function(){return{id:r.jobId,status:r.jobStatus,results:v(t,function(e){return e.value().value}),messages:r.messages}})];case 3:return[2,{id:r.jobId,status:r.jobStatus,results:void 0,messages:r.messages}]}})})})]}})})},i.prototype.needToWaitForJobCompletion=function(){return o.isArcGisApiVersionAtLeast("4.13")},i.prototype.populateResults=function(r,i,n){return l.__awaiter(this,void 0,void 0,function(){var t,o,s;return l.__generator(this,function(e){switch(e.label){case 0:return t=r.indexOf("?"),o=r,s="",-1!==t&&(o=r.substring(0,t),s=r.substring(t)),s=s?s+"&f=json":"?f=json",s=o+"/jobs/"+i.jobId+s,[4,a.default(s,n)];case 1:return(s=e.sent())&&s.data&&(i.results=s.data.results),[2]}})})},i.action="gcx:wf:arcgis::GeoprocessingAsync",i.suite="gcx:wf:builtin",s=l.__decorate([r.activate(s.MapProvider)],i);function i(){}t.GeoprocessingAsync=s});