summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/worker_threads.ts
diff options
context:
space:
mode:
authorMarvin Hagemeister <hello@marvinh.dev>2023-05-11 12:32:19 +0200
committerGitHub <noreply@github.com>2023-05-11 12:32:19 +0200
commitf1d0f745d362adb2e19a54693ed10d9020e987fa (patch)
treecf4086b95123952cd28883a03c2e1df82a7c79bb /ext/node/polyfills/worker_threads.ts
parent28aa489de9cd4f995ec2fc02e2c9d224e89f4c01 (diff)
fix(node): expose channels in worker_threads (#19086)
This PR ensures that node's `worker_threads` module exports `MessageChannel`, `MessagePort` and the `BroadcastChannel` API. Fixing these won't make `esbuild` work, but brings us one step closer 🎉 Fixes #19028 .
Diffstat (limited to 'ext/node/polyfills/worker_threads.ts')
-rw-r--r--ext/node/polyfills/worker_threads.ts17
1 files changed, 7 insertions, 10 deletions
diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts
index cc9529fbd..2c13e4bc8 100644
--- a/ext/node/polyfills/worker_threads.ts
+++ b/ext/node/polyfills/worker_threads.ts
@@ -4,6 +4,8 @@
import { resolve, toFileUrl } from "ext:deno_node/path.ts";
import { notImplemented } from "ext:deno_node/_utils.ts";
import { EventEmitter } from "ext:deno_node/events.ts";
+import { BroadcastChannel } from "ext:deno_broadcast_channel/01_broadcast_channel.js";
+import { MessageChannel, MessagePort } from "ext:deno_web/13_message_port.js";
const environmentData = new Map();
let threads = 0;
@@ -204,12 +206,6 @@ export function setEnvironmentData(key: unknown, value?: unknown) {
}
}
-// deno-lint-ignore no-explicit-any
-const _MessagePort: typeof MessagePort = (globalThis as any).MessagePort;
-const _MessageChannel: typeof MessageChannel =
- // deno-lint-ignore no-explicit-any
- (globalThis as any).MessageChannel;
-export const BroadcastChannel = globalThis.BroadcastChannel;
export const SHARE_ENV = Symbol.for("nodejs.worker_threads.SHARE_ENV");
export function markAsUntransferable() {
notImplemented("markAsUntransferable");
@@ -221,9 +217,10 @@ export function receiveMessageOnPort() {
notImplemented("receiveMessageOnPort");
}
export {
- _MessageChannel as MessageChannel,
- _MessagePort as MessagePort,
_Worker as Worker,
+ BroadcastChannel,
+ MessageChannel,
+ MessagePort,
parentPort,
threadId,
workerData,
@@ -233,8 +230,8 @@ export default {
markAsUntransferable,
moveMessagePortToContext,
receiveMessageOnPort,
- MessagePort: _MessagePort,
- MessageChannel: _MessageChannel,
+ MessagePort,
+ MessageChannel,
BroadcastChannel,
Worker: _Worker,
getEnvironmentData,