mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
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 .
This commit is contained in:
parent
75735fbf7f
commit
ff1403c0a1
4 changed files with 28 additions and 10 deletions
|
@ -655,6 +655,8 @@
|
||||||
"test-whatwg-url-override-hostname.js",
|
"test-whatwg-url-override-hostname.js",
|
||||||
"test-whatwg-url-properties.js",
|
"test-whatwg-url-properties.js",
|
||||||
"test-whatwg-url-toascii.js",
|
"test-whatwg-url-toascii.js",
|
||||||
|
"test-worker-threads-broadcast-channel.js",
|
||||||
|
"test-worker-threads-message-channel.js",
|
||||||
"test-zlib-close-after-error.js",
|
"test-zlib-close-after-error.js",
|
||||||
"test-zlib-close-after-write.js",
|
"test-zlib-close-after-write.js",
|
||||||
"test-zlib-convenience-methods.js",
|
"test-zlib-convenience-methods.js",
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
// deno-fmt-ignore-file
|
||||||
|
// deno-lint-ignore-file
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const assert = require("assert/strict");
|
||||||
|
const worker_threads = require("worker_threads");
|
||||||
|
|
||||||
|
assert.equal(BroadcastChannel, worker_threads.BroadcastChannel);
|
|
@ -0,0 +1,10 @@
|
||||||
|
// deno-fmt-ignore-file
|
||||||
|
// deno-lint-ignore-file
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const assert = require("assert/strict");
|
||||||
|
const worker_threads = require("worker_threads");
|
||||||
|
|
||||||
|
assert.equal(MessageChannel, worker_threads.MessageChannel);
|
||||||
|
assert.equal(MessagePort, worker_threads.MessagePort);
|
|
@ -4,6 +4,8 @@
|
||||||
import { resolve, toFileUrl } from "ext:deno_node/path.ts";
|
import { resolve, toFileUrl } from "ext:deno_node/path.ts";
|
||||||
import { notImplemented } from "ext:deno_node/_utils.ts";
|
import { notImplemented } from "ext:deno_node/_utils.ts";
|
||||||
import { EventEmitter } from "ext:deno_node/events.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();
|
const environmentData = new Map();
|
||||||
let threads = 0;
|
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 const SHARE_ENV = Symbol.for("nodejs.worker_threads.SHARE_ENV");
|
||||||
export function markAsUntransferable() {
|
export function markAsUntransferable() {
|
||||||
notImplemented("markAsUntransferable");
|
notImplemented("markAsUntransferable");
|
||||||
|
@ -221,9 +217,10 @@ export function receiveMessageOnPort() {
|
||||||
notImplemented("receiveMessageOnPort");
|
notImplemented("receiveMessageOnPort");
|
||||||
}
|
}
|
||||||
export {
|
export {
|
||||||
_MessageChannel as MessageChannel,
|
|
||||||
_MessagePort as MessagePort,
|
|
||||||
_Worker as Worker,
|
_Worker as Worker,
|
||||||
|
BroadcastChannel,
|
||||||
|
MessageChannel,
|
||||||
|
MessagePort,
|
||||||
parentPort,
|
parentPort,
|
||||||
threadId,
|
threadId,
|
||||||
workerData,
|
workerData,
|
||||||
|
@ -233,8 +230,8 @@ export default {
|
||||||
markAsUntransferable,
|
markAsUntransferable,
|
||||||
moveMessagePortToContext,
|
moveMessagePortToContext,
|
||||||
receiveMessageOnPort,
|
receiveMessageOnPort,
|
||||||
MessagePort: _MessagePort,
|
MessagePort,
|
||||||
MessageChannel: _MessageChannel,
|
MessageChannel,
|
||||||
BroadcastChannel,
|
BroadcastChannel,
|
||||||
Worker: _Worker,
|
Worker: _Worker,
|
||||||
getEnvironmentData,
|
getEnvironmentData,
|
||||||
|
|
Loading…
Reference in a new issue