1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-12 18:42:18 -05:00
denoland-deno/cli/tests/testdata/compat/worker/worker_test.mjs
2022-07-20 16:56:53 +02:00

18 lines
491 B
JavaScript

import { deferred } from "../../../../../test_util/std/async/deferred.ts";
const promise = deferred();
const url = import.meta.resolve("./worker.mjs");
const worker = new Worker(url, { type: "module" });
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();