function m(n){let i=0,s=new Map;return n.onmessage=t=>{let e=t.data;if(e.type==="pong")return;let r=s.get(e.id);r&&(s.delete(e.id),e.type==="error"?r.reject(new Error(e.message)):e.type==="result"?r.resolve(e.result):e.type==="analyzed"?r.resolve({waferSummaries:e.waferSummaries,lotSummary:e.lotSummary}):e.type==="resultWithAnalysis"&&r.resolve({results:e.results,waferSummaries:e.waferSummaries,lotSummary:e.lotSummary}))},n.onerror=t=>{let e=new Error(t.message??"Worker error");for(let r of s.values())r.reject(e);s.clear()},{run(t){return new Promise((e,r)=>{let a=i++;s.set(a,{resolve:e,reject:r}),n.postMessage({type:"run",id:a,input:t})})},runAnalysis(t,e,r){return new Promise((a,l)=>{let o=i++;s.set(o,{resolve:a,reject:l}),n.postMessage({type:"analyze",id:o,results:t,options:e,hasMultiWafer:r})})},runWithAnalysis(t,e,r){return new Promise((a,l)=>{let o=i++;s.set(o,{resolve:a,reject:l}),n.postMessage({type:"runWithAnalysis",id:o,inputs:t,options:e,hasMultiWafer:r})})},terminate(){n.terminate();let t=new Error("Worker terminated");for(let e of s.values())e.reject(t);s.clear()}}}export{m as createWafermapWorker};
