1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-15 03:48:02 -05:00
denoland-deno/cli/tests/testdata/compile/workers/worker.ts
Andreu Botella 090169cfbc
feat(compile): Add support for web workers in standalone mode (#17657)
This commit adds support for spawning Web Workers in self-contained
binaries created with "deno compile" subcommand.

As long as module requested in "new Worker" constructor is part of the
eszip (by means of statically importing it beforehand, or using "--include"
flag), then the worker can be spawned.
2023-03-19 23:32:54 +01:00

14 lines
338 B
TypeScript

/// <reference no-default-lib="true" />
/// <reference lib="deno.worker" />
if (import.meta.main) {
console.log("Hello from worker!");
addEventListener("message", (evt) => {
console.log(`Received ${evt.data}`);
console.log("Closing");
self.close();
});
} else {
console.log("worker.js imported from main thread");
}