summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/worker_threads.ts
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2024-04-09 23:45:55 +0530
committerGitHub <noreply@github.com>2024-04-09 20:15:55 +0200
commit5a3ee6d9af875af032909489c0bed7db11b608dd (patch)
tree894744a0811b21179a65ee63858f50fbe4fc64d9 /ext/node/polyfills/worker_threads.ts
parentfad12b7c2ebd87a2a11f63998f4c2549fd405eff (diff)
fix(ext/node): implement MessagePort.unref() (#23278)
Closes https://github.com/denoland/deno/issues/23252 Closes https://github.com/denoland/deno/issues/23264
Diffstat (limited to 'ext/node/polyfills/worker_threads.ts')
-rw-r--r--ext/node/polyfills/worker_threads.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts
index 3c8c9d443..323095206 100644
--- a/ext/node/polyfills/worker_threads.ts
+++ b/ext/node/polyfills/worker_threads.ts
@@ -18,7 +18,9 @@ import {
MessagePortIdSymbol,
MessagePortPrototype,
nodeWorkerThreadCloseCb,
+ refMessagePort,
serializeJsMessageData,
+ unrefPollForMessages,
} from "ext:deno_web/13_message_port.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { notImplemented } from "ext:deno_node/_utils.ts";
@@ -398,6 +400,12 @@ internals.__initWorkerThreads = (
parentPort.addEventListener("offline", () => {
parentPort.emit("close");
});
+ parentPort.unref = () => {
+ parentPort[unrefPollForMessages] = true;
+ };
+ parentPort.ref = () => {
+ parentPort[unrefPollForMessages] = false;
+ };
}
};
@@ -467,6 +475,12 @@ function webMessagePortToNodeMessagePort(port: MessagePort) {
port[nodeWorkerThreadCloseCb] = () => {
port.dispatchEvent(new Event("close"));
};
+ port.unref = () => {
+ port[refMessagePort](false);
+ };
+ port.ref = () => {
+ port[refMessagePort](true);
+ };
return port;
}