mirror of
https://github.com/denoland/deno.git
synced 2024-12-30 11:16:38 -05:00
2fa0096821
Adds another callback to WebWorkerOptions that allows to execute some modules before actual worker code executes. This allows to set up Node global using std/node.
18 lines
513 B
JavaScript
18 lines
513 B
JavaScript
import { deferred } from "../../../../../test_util/std/async/deferred.ts";
|
|
|
|
const promise = deferred();
|
|
const url = new URL("./worker.mjs", import.meta.url);
|
|
const worker = new Worker(url.href, { type: "module", deno: true });
|
|
|
|
worker.onmessage = (e) => {
|
|
const pid = e.data.pid;
|
|
if (typeof pid != "number") {
|
|
throw new Error("pid is not a number");
|
|
}
|
|
console.log("process.pid from worker:", pid);
|
|
promise.resolve();
|
|
};
|
|
|
|
worker.postMessage("hello");
|
|
await promise;
|
|
worker.terminate();
|