{"version":3,"file":"worker.cjs","sources":["../../src/worker.ts"],"sourcesContent":["import type { Resolvable } from \"@vibrant/types\";\nimport type {\n\tWorkerErrorResponse,\n\tWorkerRequest,\n\tWorkerResponse,\n} from \"./common\";\n\nexport function runInWorker<R>(\n\tself: Window,\n\tfn: (...args: any[]) => Resolvable<R>,\n) {\n\tself.onmessage = (event) => {\n\t\tconst data: WorkerRequest = event.data;\n\n\t\tconst { id, payload } = data;\n\n\t\tlet response: WorkerResponse<R> | WorkerErrorResponse;\n\n\t\tPromise.resolve(fn(...payload))\n\t\t\t.then((ret) => {\n\t\t\t\t(self as any).postMessage({\n\t\t\t\t\tid,\n\t\t\t\t\ttype: \"return\",\n\t\t\t\t\tpayload: ret,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((e) => {\n\t\t\t\t(self as any).postMessage({\n\t\t\t\t\tid,\n\t\t\t\t\ttype: \"error\",\n\t\t\t\t\tpayload: (e as Error).message,\n\t\t\t\t});\n\t\t\t});\n\t};\n}\n"],"names":[],"mappings":";;AAOO,SAAS,YACf,MACA,IACC;AACD,OAAK,YAAY,CAAC,UAAU;AAC3B,UAAM,OAAsB,MAAM;AAElC,UAAM,EAAE,IAAI,QAAA,IAAY;AAIxB,YAAQ,QAAQ,GAAG,GAAG,OAAO,CAAC,EAC5B,KAAK,CAAC,QAAQ;AACb,WAAa,YAAY;AAAA,QACzB;AAAA,QACA,MAAM;AAAA,QACN,SAAS;AAAA,MAAA,CACT;AAAA,IACF,CAAC,EACA,MAAM,CAAC,MAAM;AACZ,WAAa,YAAY;AAAA,QACzB;AAAA,QACA,MAAM;AAAA,QACN,SAAU,EAAY;AAAA,MAAA,CACtB;AAAA,IACF,CAAC;AAAA,EACH;AACD;;"}