// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/layers/vectorTiles/core/workers/WorkerProxy",["require","exports","dojo/Deferred","../Error"],function(m,n,k,l){return function(){function g(a,f,d){this.parentModule=a;this.worker=f;this.connection=d;this.msgCount=0;this.outgoingJobs=new Map;this.incomingJobs=new Map}g.prototype.invoke=function(a,f,d,c){var b=this,e=++this.msgCount,h=new k(function(a){b.worker.postMessage({type:"\x3ccancel\x3e",id:e,connection:c,data:{reason:a}});if(b.outgoingJobs.has(e))b.outgoingJobs["delete"](e)});
this.outgoingJobs.set(e,h);this.worker.postMessage({type:a,id:e,connection:c,data:f},d);return h.promise};g.prototype.message=function(a){var f=this;if(a&&a.data){var d=a.data.type;if(d){var c=a.data,b=a.data.id,e=a.data.connection;if("\x3cresponse\x3e"===d&&b){if(a=this.outgoingJobs.get(b))this.outgoingJobs["delete"](b),c.error?a.reject(l.fromJSON(c.error)):a.resolve(c.data)}else"\x3ccancel\x3e"===d&&b?(a=this.incomingJobs.get(b))&&a.cancel(c.data.reason||"cancel"):(a=this.parentModule[d],"function"===
typeof a&&(c=a.call(this.parentModule,c.data,this.connection),this.incomingJobs.set(b,c),c.then(function(a){f.worker.postMessage({type:"\x3cresponse\x3e",id:b,connection:e,data:a&&null!=a.data?a.data:a},a&&a.buffers||[])}).otherwise(function(a){a||(a={message:"Error encountered at method "+d});f.worker.postMessage({type:"\x3cresponse\x3e",id:b,connection:e,data:null,error:{message:a.message,stack:a.stack}})}).always(function(){f.incomingJobs["delete"](b)})))}}};return g}()});