mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 01:18:34 +00:00
Trying a documented wya of running a shared worker.
This commit is contained in:
1 parent
c3c44f7709
commit
f768781997
1 file changed
+15
-10
@@ -3,7 +3,10 @@ import {
|
||||
SharedWorkerResponse,
|
||||
} from "~/KonvaApp/WorkerPrimitives/SharedWorkerBase";
|
||||
import { ResponseType } from "~/KonvaApp/WorkerPrimitives/SharedWorkerBase";
|
||||
import diffusionWorkerURL from "~/KonvaApp/SharedWorkers/Diffusion/DiffusionSharedWorker.ts?worker&url";
|
||||
// import diffusionWorkerURL from "DiffusionSharedWorker.js?worker&url";
|
||||
// import diff from "~/KonvaApp/WorkerPrimitives/SharedWorkerBa"
|
||||
|
||||
import worker from "~/KonvaApp/SharedWorker/DiffusionSharedWorker.ts?sharedworker";
|
||||
export class DiffusionSharedWorkerClient<
|
||||
DiffusionSharedWorkerItemData,
|
||||
DiffusionSharedWorkerResponseData,
|
||||
@@ -34,18 +37,20 @@ export class DiffusionSharedWorkerClient<
|
||||
});
|
||||
} else {
|
||||
console.log("This is running a worker in production");
|
||||
|
||||
this.sharedWorker = new SharedWorker("workers/DiffusionSharedWorker.js", {
|
||||
const url = new URL("DiffusionSharedWorker.ts", import.meta.url);
|
||||
console.log(url);
|
||||
this.sharedWorker = new SharedWorker(url, {
|
||||
type: "module",
|
||||
});
|
||||
// // in production this is a work around .. https://github.com/vitejs/vite/issues/13680
|
||||
// const js = `import ${JSON.stringify(new URL(diffusionWorkerURL, import.meta.url))}`;
|
||||
// const blob = new Blob([js], { type: "application/javascript" });
|
||||
// const objURL = URL.createObjectURL(blob);
|
||||
// this.sharedWorker = new SharedWorker(new URL(objURL, import.meta.url), {
|
||||
// type: "module",
|
||||
// });
|
||||
}
|
||||
// // in production this is a work around .. https://github.com/vitejs/vite/issues/13680
|
||||
// const js = `import ${JSON.stringify(new URL(diffusionWorkerURL, import.meta.url))}`;
|
||||
// const blob = new Blob([js], { type: "application/javascript" });
|
||||
// const objURL = URL.createObjectURL(blob);
|
||||
// this.sharedWorker = new SharedWorker(new URL(objURL, import.meta.url), {
|
||||
// type: "module",
|
||||
// });
|
||||
//}
|
||||
this.port = this.sharedWorker.port;
|
||||
this.port.onmessage = this.onMessage.bind(this);
|
||||
this.port.start();
|
||||
|
||||
Reference in new issue
Block a user