Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions types/node/test/worker_threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,11 @@ import { createContext } from "node:vm";
const arrayBuffer = new ArrayBuffer(0);
structuredClone({ test: arrayBuffer }, { transfer: [arrayBuffer] }); // $ExpectType { test: ArrayBuffer; }
}

{
const { port1 } = new workerThreads.MessageChannel();
workerThreads.postMessageToThread(10, { port: port1 }, [port1], 1000);
workerThreads.postMessageToThread(10, { port: port1 }, [port1]);
workerThreads.postMessageToThread(10, { x: 100 }, 1000);
workerThreads.postMessageToThread(10, { x: 100 });
}
8 changes: 8 additions & 0 deletions types/node/v20/test/worker_threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,11 @@ import { createContext } from "node:vm";
const arrayBuffer = new ArrayBuffer(0);
structuredClone({ test: arrayBuffer }, { transfer: [arrayBuffer] }); // $ExpectType { test: ArrayBuffer; }
}

{
const { port1 } = new workerThreads.MessageChannel();
workerThreads.postMessageToThread(10, { port: port1 }, [port1], 1000);
workerThreads.postMessageToThread(10, { port: port1 }, [port1]);
workerThreads.postMessageToThread(10, { x: 100 }, 1000);
workerThreads.postMessageToThread(10, { x: 100 });
}
18 changes: 18 additions & 0 deletions types/node/v20/worker_threads.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,24 @@ declare module "worker_threads" {
* for the `key` will be deleted.
*/
function setEnvironmentData(key: Serializable, value?: Serializable): void;
/**
* Sends a value to another worker, identified by its thread ID.
* @param threadId The target thread ID. If the thread ID is invalid, a `ERR_WORKER_MESSAGING_FAILED` error will be thrown.
* If the target thread ID is the current thread ID, a `ERR_WORKER_MESSAGING_SAME_THREAD` error will be thrown.
* @param value The value to send.
* @param transferList If one or more `MessagePort`-like objects are passed in value, a `transferList` is required for those items
* or `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST` is thrown. See `port.postMessage()` for more information.
* @param timeout Time to wait for the message to be delivered in milliseconds. By default it's `undefined`, which means wait forever.
* If the operation times out, a `ERR_WORKER_MESSAGING_TIMEOUT` error is thrown.
* @since v22.5.0
*/
function postMessageToThread(threadId: number, value: any, timeout?: number): Promise<void>;
function postMessageToThread(
threadId: number,
value: any,
transferList: readonly Transferable[],
timeout?: number,
): Promise<void>;

import {
BroadcastChannel as _BroadcastChannel,
Expand Down
8 changes: 8 additions & 0 deletions types/node/v22/test/worker_threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,11 @@ import { createContext } from "node:vm";
const arrayBuffer = new ArrayBuffer(0);
structuredClone({ test: arrayBuffer }, { transfer: [arrayBuffer] }); // $ExpectType { test: ArrayBuffer; }
}

{
const { port1 } = new workerThreads.MessageChannel();
workerThreads.postMessageToThread(10, { port: port1 }, [port1], 1000);
workerThreads.postMessageToThread(10, { port: port1 }, [port1]);
workerThreads.postMessageToThread(10, { x: 100 }, 1000);
workerThreads.postMessageToThread(10, { x: 100 });
}
18 changes: 18 additions & 0 deletions types/node/v22/worker_threads.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,24 @@ declare module "worker_threads" {
* for the `key` will be deleted.
*/
function setEnvironmentData(key: Serializable, value?: Serializable): void;
/**
* Sends a value to another worker, identified by its thread ID.
* @param threadId The target thread ID. If the thread ID is invalid, a `ERR_WORKER_MESSAGING_FAILED` error will be thrown.
* If the target thread ID is the current thread ID, a `ERR_WORKER_MESSAGING_SAME_THREAD` error will be thrown.
* @param value The value to send.
* @param transferList If one or more `MessagePort`-like objects are passed in value, a `transferList` is required for those items
* or `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST` is thrown. See `port.postMessage()` for more information.
* @param timeout Time to wait for the message to be delivered in milliseconds. By default it's `undefined`, which means wait forever.
* If the operation times out, a `ERR_WORKER_MESSAGING_TIMEOUT` error is thrown.
* @since v22.5.0
*/
function postMessageToThread(threadId: number, value: any, timeout?: number): Promise<void>;
function postMessageToThread(
threadId: number,
value: any,
transferList: readonly Transferable[],
timeout?: number,
): Promise<void>;

import {
BroadcastChannel as _BroadcastChannel,
Expand Down
18 changes: 18 additions & 0 deletions types/node/worker_threads.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,24 @@ declare module "worker_threads" {
* for the `key` will be deleted.
*/
function setEnvironmentData(key: Serializable, value?: Serializable): void;
/**
* Sends a value to another worker, identified by its thread ID.
* @param threadId The target thread ID. If the thread ID is invalid, a `ERR_WORKER_MESSAGING_FAILED` error will be thrown.
* If the target thread ID is the current thread ID, a `ERR_WORKER_MESSAGING_SAME_THREAD` error will be thrown.
* @param value The value to send.
* @param transferList If one or more `MessagePort`-like objects are passed in value, a `transferList` is required for those items
* or `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST` is thrown. See `port.postMessage()` for more information.
* @param timeout Time to wait for the message to be delivered in milliseconds. By default it's `undefined`, which means wait forever.
* If the operation times out, a `ERR_WORKER_MESSAGING_TIMEOUT` error is thrown.
* @since v22.5.0
*/
function postMessageToThread(threadId: number, value: any, timeout?: number): Promise<void>;
function postMessageToThread(
threadId: number,
value: any,
transferList: readonly Transferable[],
timeout?: number,
): Promise<void>;

import {
BroadcastChannel as _BroadcastChannel,
Expand Down