diff options
author | Satya Rohith <me@satyarohith.com> | 2024-05-03 11:22:47 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-03 05:52:47 +0000 |
commit | 02d0ff58d2bab24ebbd1e61afe6b571ff4c415af (patch) | |
tree | 78b7fa4e7cf0265d688e34ddaa422ec344273e06 /tests/specs/node/worker_threads/auto_exits.mjs | |
parent | 3e98ea4e69732d8a659ca0ca61747fe3887ab673 (diff) |
refactor(tests): move worker_threads itests to spec tests (#23648)
Diffstat (limited to 'tests/specs/node/worker_threads/auto_exits.mjs')
-rw-r--r-- | tests/specs/node/worker_threads/auto_exits.mjs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/specs/node/worker_threads/auto_exits.mjs b/tests/specs/node/worker_threads/auto_exits.mjs new file mode 100644 index 000000000..e434f59f7 --- /dev/null +++ b/tests/specs/node/worker_threads/auto_exits.mjs @@ -0,0 +1,19 @@ +import { isMainThread, parentPort, Worker } from "node:worker_threads"; + +function onMessageOneshot() { + console.log("Got message from main thread!"); + parentPort.off("message", onMessageOneshot); +} + +if (isMainThread) { + // This re-loads the current file inside a Worker instance. + const w = new Worker(import.meta.filename); + + setTimeout(() => { + w.postMessage("Hello! I am from the main thread."); + }, 500); +} else { + console.log("Inside Worker!"); + console.log(isMainThread); // Prints 'false'. + parentPort.on("message", onMessageOneshot); +} |