@rio-cloud/cdk-v2-constructs 8.2.0 → 8.2.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +2 -2
- package/node_modules/@types/node/README.md +3 -3
- package/node_modules/@types/node/assert/strict.d.ts +105 -2
- package/node_modules/@types/node/assert.d.ts +211 -92
- package/node_modules/@types/node/async_hooks.d.ts +103 -19
- package/node_modules/@types/node/buffer.buffer.d.ts +472 -0
- package/node_modules/@types/node/buffer.d.ts +88 -516
- package/node_modules/@types/node/child_process.d.ts +167 -231
- package/node_modules/@types/node/cluster.d.ts +172 -26
- package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/node_modules/@types/node/console.d.ts +66 -28
- package/node_modules/@types/node/constants.d.ts +14 -12
- package/node_modules/@types/node/crypto.d.ts +1458 -497
- package/node_modules/@types/node/dgram.d.ts +44 -30
- package/node_modules/@types/node/diagnostics_channel.d.ts +389 -4
- package/node_modules/@types/node/dns/promises.d.ts +120 -42
- package/node_modules/@types/node/dns.d.ts +209 -95
- package/node_modules/@types/node/domain.d.ts +14 -18
- package/node_modules/@types/node/events.d.ts +245 -113
- package/node_modules/@types/node/fs/promises.d.ts +194 -96
- package/node_modules/@types/node/fs.d.ts +695 -270
- package/node_modules/@types/node/globals.d.ts +97 -308
- package/node_modules/@types/node/globals.typedarray.d.ts +41 -0
- package/node_modules/@types/node/http.d.ts +363 -97
- package/node_modules/@types/node/http2.d.ts +684 -231
- package/node_modules/@types/node/https.d.ts +122 -87
- package/node_modules/@types/node/index.d.ts +24 -11
- package/node_modules/@types/node/inspector.d.ts +220 -2690
- package/node_modules/@types/node/inspector.generated.d.ts +4239 -0
- package/node_modules/@types/node/module.d.ts +705 -149
- package/node_modules/@types/node/net.d.ts +178 -54
- package/node_modules/@types/node/os.d.ts +47 -17
- package/node_modules/@types/node/package.json +22 -97
- package/node_modules/@types/node/path.d.ts +12 -3
- package/node_modules/@types/node/perf_hooks.d.ts +500 -97
- package/node_modules/@types/node/process.d.ts +657 -87
- package/node_modules/@types/node/punycode.d.ts +5 -5
- package/node_modules/@types/node/querystring.d.ts +24 -13
- package/node_modules/@types/node/readline/promises.d.ts +25 -14
- package/node_modules/@types/node/readline.d.ts +102 -41
- package/node_modules/@types/node/repl.d.ts +38 -30
- package/node_modules/@types/node/sea.d.ts +162 -0
- package/node_modules/@types/node/sqlite.d.ts +1040 -0
- package/node_modules/@types/node/stream/consumers.d.ts +33 -7
- package/node_modules/@types/node/stream/promises.d.ts +8 -1
- package/node_modules/@types/node/stream/web.d.ts +251 -28
- package/node_modules/@types/node/stream.d.ts +1060 -1055
- package/node_modules/@types/node/string_decoder.d.ts +8 -8
- package/node_modules/@types/node/test.d.ts +2133 -1166
- package/node_modules/@types/node/timers/promises.d.ts +31 -16
- package/node_modules/@types/node/timers.d.ts +159 -114
- package/node_modules/@types/node/tls.d.ts +232 -163
- package/node_modules/@types/node/trace_events.d.ts +43 -28
- package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
- package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
- package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +103 -0
- package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
- package/node_modules/@types/node/ts5.7/index.d.ts +103 -0
- package/node_modules/@types/node/tty.d.ts +9 -9
- package/node_modules/@types/node/url.d.ts +236 -84
- package/node_modules/@types/node/util.d.ts +562 -412
- package/node_modules/@types/node/v8.d.ts +368 -21
- package/node_modules/@types/node/vm.d.ts +443 -149
- package/node_modules/@types/node/wasi.d.ts +62 -18
- package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
- package/node_modules/@types/node/web-globals/crypto.d.ts +32 -0
- package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
- package/node_modules/@types/node/web-globals/events.d.ts +97 -0
- package/node_modules/@types/node/web-globals/fetch.d.ts +62 -0
- package/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
- package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
- package/node_modules/@types/node/web-globals/streams.d.ts +22 -0
- package/node_modules/@types/node/worker_threads.d.ts +310 -107
- package/node_modules/@types/node/zlib.d.ts +301 -73
- package/node_modules/undici-types/LICENSE +21 -0
- package/node_modules/undici-types/agent.d.ts +13 -12
- package/node_modules/undici-types/api.d.ts +26 -26
- package/node_modules/undici-types/balanced-pool.d.ts +19 -7
- package/node_modules/undici-types/cache-interceptor.d.ts +173 -0
- package/node_modules/undici-types/client-stats.d.ts +15 -0
- package/node_modules/undici-types/client.d.ts +26 -15
- package/node_modules/undici-types/connector.d.ts +2 -2
- package/node_modules/undici-types/cookies.d.ts +2 -0
- package/node_modules/undici-types/diagnostics-channel.d.ts +19 -12
- package/node_modules/undici-types/dispatcher.d.ts +148 -113
- package/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
- package/node_modules/undici-types/errors.d.ts +79 -46
- package/node_modules/undici-types/eventsource.d.ts +66 -0
- package/node_modules/undici-types/fetch.d.ts +41 -39
- package/node_modules/undici-types/formdata.d.ts +8 -8
- package/node_modules/undici-types/global-dispatcher.d.ts +4 -4
- package/node_modules/undici-types/global-origin.d.ts +5 -5
- package/node_modules/undici-types/h2c-client.d.ts +73 -0
- package/node_modules/undici-types/handlers.d.ts +11 -5
- package/node_modules/undici-types/header.d.ts +157 -1
- package/node_modules/undici-types/index.d.ts +68 -43
- package/node_modules/undici-types/interceptors.d.ts +71 -3
- package/node_modules/undici-types/mock-agent.d.ts +36 -18
- package/node_modules/undici-types/mock-call-history.d.ts +111 -0
- package/node_modules/undici-types/mock-client.d.ts +6 -4
- package/node_modules/undici-types/mock-errors.d.ts +3 -3
- package/node_modules/undici-types/mock-interceptor.d.ts +24 -23
- package/node_modules/undici-types/mock-pool.d.ts +6 -4
- package/node_modules/undici-types/package.json +1 -1
- package/node_modules/undici-types/patch.d.ts +0 -42
- package/node_modules/undici-types/pool-stats.d.ts +8 -8
- package/node_modules/undici-types/pool.d.ts +21 -8
- package/node_modules/undici-types/proxy-agent.d.ts +5 -6
- package/node_modules/undici-types/readable.d.ts +24 -17
- package/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/node_modules/undici-types/retry-handler.d.ts +125 -0
- package/node_modules/undici-types/round-robin-pool.d.ts +41 -0
- package/node_modules/undici-types/snapshot-agent.d.ts +109 -0
- package/node_modules/undici-types/util.d.ts +18 -0
- package/node_modules/undici-types/utility.d.ts +7 -0
- package/node_modules/undici-types/webidl.d.ts +157 -36
- package/node_modules/undici-types/websocket.d.ts +67 -12
- package/package.json +9 -60
- package/version.json +1 -1
- package/node_modules/@types/node/dom-events.d.ts +0 -122
- package/node_modules/@types/node/globals.global.d.ts +0 -1
- package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/ts4.8/assert.d.ts +0 -996
- package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2362
- package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1540
- package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
- package/node_modules/@types/node/ts4.8/console.d.ts +0 -415
- package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
- package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4455
- package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -586
- package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -191
- package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -425
- package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
- package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
- package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
- package/node_modules/@types/node/ts4.8/events.d.ts +0 -796
- package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1232
- package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4289
- package/node_modules/@types/node/ts4.8/globals.d.ts +0 -381
- package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
- package/node_modules/@types/node/ts4.8/http.d.ts +0 -1888
- package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2382
- package/node_modules/@types/node/ts4.8/https.d.ts +0 -550
- package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
- package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2747
- package/node_modules/@types/node/ts4.8/module.d.ts +0 -287
- package/node_modules/@types/node/ts4.8/net.d.ts +0 -949
- package/node_modules/@types/node/ts4.8/os.d.ts +0 -477
- package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
- package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -639
- package/node_modules/@types/node/ts4.8/process.d.ts +0 -1532
- package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
- package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
- package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -150
- package/node_modules/@types/node/ts4.8/readline.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
- package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -350
- package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1701
- package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/ts4.8/test.d.ts +0 -1382
- package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/ts4.8/timers.d.ts +0 -240
- package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1210
- package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -182
- package/node_modules/@types/node/ts4.8/tty.d.ts +0 -208
- package/node_modules/@types/node/ts4.8/url.d.ts +0 -927
- package/node_modules/@types/node/ts4.8/util.d.ts +0 -2186
- package/node_modules/@types/node/ts4.8/v8.d.ts +0 -635
- package/node_modules/@types/node/ts4.8/vm.d.ts +0 -901
- package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -158
- package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -691
- package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
- package/node_modules/argparse/CHANGELOG.md +0 -216
- package/node_modules/undici-types/file.d.ts +0 -39
- package/node_modules/undici-types/filereader.d.ts +0 -54
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* JavaScript in parallel. To access it:
|
|
4
4
|
*
|
|
5
5
|
* ```js
|
|
6
|
-
*
|
|
6
|
+
* import worker_threads from 'node:worker_threads';
|
|
7
7
|
* ```
|
|
8
8
|
*
|
|
9
9
|
* Workers (threads) are useful for performing CPU-intensive JavaScript operations.
|
|
@@ -11,32 +11,35 @@
|
|
|
11
11
|
* asynchronous I/O operations are more efficient than Workers can be.
|
|
12
12
|
*
|
|
13
13
|
* Unlike `child_process` or `cluster`, `worker_threads` can share memory. They do
|
|
14
|
-
* so by transferring `ArrayBuffer` instances or sharing `SharedArrayBuffer`instances.
|
|
14
|
+
* so by transferring `ArrayBuffer` instances or sharing `SharedArrayBuffer` instances.
|
|
15
15
|
*
|
|
16
16
|
* ```js
|
|
17
|
-
*
|
|
18
|
-
* Worker,
|
|
19
|
-
*
|
|
17
|
+
* import {
|
|
18
|
+
* Worker,
|
|
19
|
+
* isMainThread,
|
|
20
|
+
* parentPort,
|
|
21
|
+
* workerData,
|
|
22
|
+
* } from 'node:worker_threads';
|
|
20
23
|
*
|
|
21
|
-
* if (isMainThread) {
|
|
22
|
-
*
|
|
23
|
-
* return new Promise((resolve, reject) => {
|
|
24
|
-
* const worker = new Worker(__filename, {
|
|
25
|
-
* workerData: script,
|
|
26
|
-
* });
|
|
27
|
-
* worker.on('message', resolve);
|
|
28
|
-
* worker.on('error', reject);
|
|
29
|
-
* worker.on('exit', (code) => {
|
|
30
|
-
* if (code !== 0)
|
|
31
|
-
* reject(new Error(`Worker stopped with exit code ${code}`));
|
|
32
|
-
* });
|
|
33
|
-
* });
|
|
34
|
-
* };
|
|
35
|
-
* } else {
|
|
36
|
-
* const { parse } = require('some-js-parsing-library');
|
|
24
|
+
* if (!isMainThread) {
|
|
25
|
+
* const { parse } = await import('some-js-parsing-library');
|
|
37
26
|
* const script = workerData;
|
|
38
27
|
* parentPort.postMessage(parse(script));
|
|
39
28
|
* }
|
|
29
|
+
*
|
|
30
|
+
* export default function parseJSAsync(script) {
|
|
31
|
+
* return new Promise((resolve, reject) => {
|
|
32
|
+
* const worker = new Worker(new URL(import.meta.url), {
|
|
33
|
+
* workerData: script,
|
|
34
|
+
* });
|
|
35
|
+
* worker.on('message', resolve);
|
|
36
|
+
* worker.once('error', reject);
|
|
37
|
+
* worker.once('exit', (code) => {
|
|
38
|
+
* if (code !== 0)
|
|
39
|
+
* reject(new Error(`Worker stopped with exit code ${code}`));
|
|
40
|
+
* });
|
|
41
|
+
* });
|
|
42
|
+
* };
|
|
40
43
|
* ```
|
|
41
44
|
*
|
|
42
45
|
* The above example spawns a Worker thread for each `parseJSAsync()` call. In
|
|
@@ -49,30 +52,33 @@
|
|
|
49
52
|
*
|
|
50
53
|
* Worker threads inherit non-process-specific options by default. Refer to `Worker constructor options` to know how to customize worker thread options,
|
|
51
54
|
* specifically `argv` and `execArgv` options.
|
|
52
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
55
|
+
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/worker_threads.js)
|
|
53
56
|
*/
|
|
54
57
|
declare module "worker_threads" {
|
|
55
|
-
import { Blob } from "node:buffer";
|
|
56
58
|
import { Context } from "node:vm";
|
|
57
|
-
import { EventEmitter } from "node:events";
|
|
58
|
-
import { EventLoopUtilityFunction } from "node:perf_hooks";
|
|
59
|
+
import { EventEmitter, NodeEventTarget } from "node:events";
|
|
59
60
|
import { FileHandle } from "node:fs/promises";
|
|
61
|
+
import { Performance } from "node:perf_hooks";
|
|
60
62
|
import { Readable, Writable } from "node:stream";
|
|
63
|
+
import { ReadableStream, TransformStream, WritableStream } from "node:stream/web";
|
|
61
64
|
import { URL } from "node:url";
|
|
62
|
-
import {
|
|
65
|
+
import { CPUProfileHandle, HeapInfo, HeapProfileHandle } from "node:v8";
|
|
66
|
+
import { MessageEvent } from "undici-types";
|
|
67
|
+
const isInternalThread: boolean;
|
|
63
68
|
const isMainThread: boolean;
|
|
64
69
|
const parentPort: null | MessagePort;
|
|
65
70
|
const resourceLimits: ResourceLimits;
|
|
66
71
|
const SHARE_ENV: unique symbol;
|
|
67
72
|
const threadId: number;
|
|
73
|
+
const threadName: string | null;
|
|
68
74
|
const workerData: any;
|
|
69
75
|
/**
|
|
70
76
|
* Instances of the `worker.MessageChannel` class represent an asynchronous,
|
|
71
77
|
* two-way communications channel.
|
|
72
|
-
* The `MessageChannel` has no methods of its own. `new MessageChannel()`yields an object with `port1` and `port2` properties, which refer to linked `MessagePort` instances.
|
|
78
|
+
* The `MessageChannel` has no methods of its own. `new MessageChannel()` yields an object with `port1` and `port2` properties, which refer to linked `MessagePort` instances.
|
|
73
79
|
*
|
|
74
80
|
* ```js
|
|
75
|
-
*
|
|
81
|
+
* import { MessageChannel } from 'node:worker_threads';
|
|
76
82
|
*
|
|
77
83
|
* const { port1, port2 } = new MessageChannel();
|
|
78
84
|
* port1.on('message', (message) => console.log('received', message));
|
|
@@ -85,22 +91,30 @@ declare module "worker_threads" {
|
|
|
85
91
|
readonly port1: MessagePort;
|
|
86
92
|
readonly port2: MessagePort;
|
|
87
93
|
}
|
|
88
|
-
interface WorkerPerformance {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
interface WorkerPerformance extends Pick<Performance, "eventLoopUtilization"> {}
|
|
95
|
+
type Transferable =
|
|
96
|
+
| ArrayBuffer
|
|
97
|
+
| MessagePort
|
|
98
|
+
| AbortSignal
|
|
99
|
+
| FileHandle
|
|
100
|
+
| ReadableStream
|
|
101
|
+
| WritableStream
|
|
102
|
+
| TransformStream;
|
|
103
|
+
/** @deprecated Use `import { Transferable } from "node:worker_threads"` instead. */
|
|
104
|
+
// TODO: remove in a future major @types/node version.
|
|
105
|
+
type TransferListItem = Transferable;
|
|
92
106
|
/**
|
|
93
107
|
* Instances of the `worker.MessagePort` class represent one end of an
|
|
94
108
|
* asynchronous, two-way communications channel. It can be used to transfer
|
|
95
|
-
* structured data, memory regions and other `MessagePort`s between different `Worker`
|
|
109
|
+
* structured data, memory regions and other `MessagePort`s between different `Worker`s.
|
|
96
110
|
*
|
|
97
111
|
* This implementation matches [browser `MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort) s.
|
|
98
112
|
* @since v10.5.0
|
|
99
113
|
*/
|
|
100
|
-
class MessagePort
|
|
114
|
+
class MessagePort implements EventTarget {
|
|
101
115
|
/**
|
|
102
116
|
* Disables further sending of messages on either side of the connection.
|
|
103
|
-
* This method can be called when no further communication will happen over this`MessagePort`.
|
|
117
|
+
* This method can be called when no further communication will happen over this `MessagePort`.
|
|
104
118
|
*
|
|
105
119
|
* The `'close' event` is emitted on both `MessagePort` instances that
|
|
106
120
|
* are part of the channel.
|
|
@@ -108,20 +122,20 @@ declare module "worker_threads" {
|
|
|
108
122
|
*/
|
|
109
123
|
close(): void;
|
|
110
124
|
/**
|
|
111
|
-
* Sends a JavaScript value to the receiving side of this channel
|
|
125
|
+
* Sends a JavaScript value to the receiving side of this channel. `value` is transferred in a way which is compatible with
|
|
112
126
|
* the [HTML structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
|
|
113
127
|
*
|
|
114
128
|
* In particular, the significant differences to `JSON` are:
|
|
115
129
|
*
|
|
116
130
|
* * `value` may contain circular references.
|
|
117
|
-
* * `value` may contain instances of builtin JS types such as `RegExp`s
|
|
131
|
+
* * `value` may contain instances of builtin JS types such as `RegExp`s, `BigInt`s, `Map`s, `Set`s, etc.
|
|
118
132
|
* * `value` may contain typed arrays, both using `ArrayBuffer`s
|
|
119
133
|
* and `SharedArrayBuffer`s.
|
|
120
134
|
* * `value` may contain [`WebAssembly.Module`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) instances.
|
|
121
135
|
* * `value` may not contain native (C++-backed) objects other than:
|
|
122
136
|
*
|
|
123
137
|
* ```js
|
|
124
|
-
*
|
|
138
|
+
* import { MessageChannel } from 'node:worker_threads';
|
|
125
139
|
* const { port1, port2 } = new MessageChannel();
|
|
126
140
|
*
|
|
127
141
|
* port1.on('message', (message) => console.log(message));
|
|
@@ -140,10 +154,10 @@ declare module "worker_threads" {
|
|
|
140
154
|
* If `value` contains [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances, those are accessible
|
|
141
155
|
* from either thread. They cannot be listed in `transferList`.
|
|
142
156
|
*
|
|
143
|
-
* `value` may still contain `ArrayBuffer` instances that are not in`transferList`; in that case, the underlying memory is copied rather than moved.
|
|
157
|
+
* `value` may still contain `ArrayBuffer` instances that are not in `transferList`; in that case, the underlying memory is copied rather than moved.
|
|
144
158
|
*
|
|
145
159
|
* ```js
|
|
146
|
-
*
|
|
160
|
+
* import { MessageChannel } from 'node:worker_threads';
|
|
147
161
|
* const { port1, port2 } = new MessageChannel();
|
|
148
162
|
*
|
|
149
163
|
* port1.on('message', (message) => console.log(message));
|
|
@@ -173,7 +187,12 @@ declare module "worker_threads" {
|
|
|
173
187
|
* behind this API, see the `serialization API of the node:v8 module`.
|
|
174
188
|
* @since v10.5.0
|
|
175
189
|
*/
|
|
176
|
-
postMessage(value: any, transferList?: readonly
|
|
190
|
+
postMessage(value: any, transferList?: readonly Transferable[]): void;
|
|
191
|
+
/**
|
|
192
|
+
* If true, the `MessagePort` object will keep the Node.js event loop active.
|
|
193
|
+
* @since v18.1.0, v16.17.0
|
|
194
|
+
*/
|
|
195
|
+
hasRef(): boolean;
|
|
177
196
|
/**
|
|
178
197
|
* Opposite of `unref()`. Calling `ref()` on a previously `unref()`ed port does _not_ let the program exit if it's the only active handle left (the default
|
|
179
198
|
* behavior). If the port is `ref()`ed, calling `ref()` again has no effect.
|
|
@@ -186,16 +205,16 @@ declare module "worker_threads" {
|
|
|
186
205
|
ref(): void;
|
|
187
206
|
/**
|
|
188
207
|
* Calling `unref()` on a port allows the thread to exit if this is the only
|
|
189
|
-
* active handle in the event system. If the port is already `unref()`ed calling`unref()` again has no effect.
|
|
208
|
+
* active handle in the event system. If the port is already `unref()`ed calling `unref()` again has no effect.
|
|
190
209
|
*
|
|
191
|
-
* If listeners are attached or removed using `.on('message')`, the port is`ref()`ed and `unref()`ed automatically depending on whether
|
|
210
|
+
* If listeners are attached or removed using `.on('message')`, the port is `ref()`ed and `unref()`ed automatically depending on whether
|
|
192
211
|
* listeners for the event exist.
|
|
193
212
|
* @since v10.5.0
|
|
194
213
|
*/
|
|
195
214
|
unref(): void;
|
|
196
215
|
/**
|
|
197
216
|
* Starts receiving messages on this `MessagePort`. When using this port
|
|
198
|
-
* as an event emitter, this is called automatically once `'message'`listeners are attached.
|
|
217
|
+
* as an event emitter, this is called automatically once `'message'` listeners are attached.
|
|
199
218
|
*
|
|
200
219
|
* This method exists for parity with the Web `MessagePort` API. In Node.js,
|
|
201
220
|
* it is only useful for ignoring messages when no event listener is present.
|
|
@@ -205,39 +224,32 @@ declare module "worker_threads" {
|
|
|
205
224
|
* @since v10.5.0
|
|
206
225
|
*/
|
|
207
226
|
start(): void;
|
|
208
|
-
addListener(event: "close", listener: () => void): this;
|
|
227
|
+
addListener(event: "close", listener: (ev: Event) => void): this;
|
|
209
228
|
addListener(event: "message", listener: (value: any) => void): this;
|
|
210
229
|
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
211
|
-
addListener(event: string
|
|
212
|
-
emit(event: "close"): boolean;
|
|
230
|
+
addListener(event: string, listener: (arg: any) => void): this;
|
|
231
|
+
emit(event: "close", ev: Event): boolean;
|
|
213
232
|
emit(event: "message", value: any): boolean;
|
|
214
233
|
emit(event: "messageerror", error: Error): boolean;
|
|
215
|
-
emit(event: string
|
|
216
|
-
|
|
234
|
+
emit(event: string, arg: any): boolean;
|
|
235
|
+
off(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
236
|
+
off(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
237
|
+
off(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
238
|
+
off(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
239
|
+
on(event: "close", listener: (ev: Event) => void): this;
|
|
217
240
|
on(event: "message", listener: (value: any) => void): this;
|
|
218
241
|
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
219
|
-
on(event: string
|
|
220
|
-
once(event: "close", listener: () => void): this;
|
|
242
|
+
on(event: string, listener: (arg: any) => void): this;
|
|
243
|
+
once(event: "close", listener: (ev: Event) => void): this;
|
|
221
244
|
once(event: "message", listener: (value: any) => void): this;
|
|
222
245
|
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
223
|
-
once(event: string
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
prependOnceListener(event: "close", listener: () => void): this;
|
|
229
|
-
prependOnceListener(event: "message", listener: (value: any) => void): this;
|
|
230
|
-
prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
231
|
-
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
232
|
-
removeListener(event: "close", listener: () => void): this;
|
|
233
|
-
removeListener(event: "message", listener: (value: any) => void): this;
|
|
234
|
-
removeListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
235
|
-
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
236
|
-
off(event: "close", listener: () => void): this;
|
|
237
|
-
off(event: "message", listener: (value: any) => void): this;
|
|
238
|
-
off(event: "messageerror", listener: (error: Error) => void): this;
|
|
239
|
-
off(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
246
|
+
once(event: string, listener: (arg: any) => void): this;
|
|
247
|
+
removeListener(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
248
|
+
removeListener(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
249
|
+
removeListener(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
250
|
+
removeListener(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
240
251
|
}
|
|
252
|
+
interface MessagePort extends NodeEventTarget {}
|
|
241
253
|
interface WorkerOptions {
|
|
242
254
|
/**
|
|
243
255
|
* List of arguments which would be stringified and appended to
|
|
@@ -257,14 +269,14 @@ declare module "worker_threads" {
|
|
|
257
269
|
/**
|
|
258
270
|
* Additional data to send in the first worker message.
|
|
259
271
|
*/
|
|
260
|
-
transferList?:
|
|
272
|
+
transferList?: Transferable[] | undefined;
|
|
261
273
|
/**
|
|
262
274
|
* @default true
|
|
263
275
|
*/
|
|
264
276
|
trackUnmanagedFds?: boolean | undefined;
|
|
265
277
|
/**
|
|
266
278
|
* An optional `name` to be appended to the worker title
|
|
267
|
-
* for
|
|
279
|
+
* for debugging/identification purposes, making the final title as
|
|
268
280
|
* `[worker ${id}] ${name}`.
|
|
269
281
|
*/
|
|
270
282
|
name?: string | undefined;
|
|
@@ -295,8 +307,8 @@ declare module "worker_threads" {
|
|
|
295
307
|
* Notable differences inside a Worker environment are:
|
|
296
308
|
*
|
|
297
309
|
* * The `process.stdin`, `process.stdout`, and `process.stderr` streams may be redirected by the parent thread.
|
|
298
|
-
* * The `
|
|
299
|
-
* * The `
|
|
310
|
+
* * The `import { isMainThread } from 'node:worker_threads'` variable is set to `false`.
|
|
311
|
+
* * The `import { parentPort } from 'node:worker_threads'` message port is available.
|
|
300
312
|
* * `process.exit()` does not stop the whole program, just the single thread,
|
|
301
313
|
* and `process.abort()` is not available.
|
|
302
314
|
* * `process.chdir()` and `process` methods that set group or user ids
|
|
@@ -331,10 +343,10 @@ declare module "worker_threads" {
|
|
|
331
343
|
* the thread barrier.
|
|
332
344
|
*
|
|
333
345
|
* ```js
|
|
334
|
-
*
|
|
335
|
-
*
|
|
346
|
+
* import assert from 'node:assert';
|
|
347
|
+
* import {
|
|
336
348
|
* Worker, MessageChannel, MessagePort, isMainThread, parentPort,
|
|
337
|
-
* }
|
|
349
|
+
* } from 'node:worker_threads';
|
|
338
350
|
* if (isMainThread) {
|
|
339
351
|
* const worker = new Worker(__filename);
|
|
340
352
|
* const subChannel = new MessageChannel();
|
|
@@ -374,11 +386,17 @@ declare module "worker_threads" {
|
|
|
374
386
|
readonly stderr: Readable;
|
|
375
387
|
/**
|
|
376
388
|
* An integer identifier for the referenced thread. Inside the worker thread,
|
|
377
|
-
* it is available as `
|
|
389
|
+
* it is available as `import { threadId } from 'node:worker_threads'`.
|
|
378
390
|
* This value is unique for each `Worker` instance inside a single process.
|
|
379
391
|
* @since v10.5.0
|
|
380
392
|
*/
|
|
381
393
|
readonly threadId: number;
|
|
394
|
+
/**
|
|
395
|
+
* A string identifier for the referenced thread or null if the thread is not running.
|
|
396
|
+
* Inside the worker thread, it is available as `require('node:worker_threads').threadName`.
|
|
397
|
+
* @since v24.6.0
|
|
398
|
+
*/
|
|
399
|
+
readonly threadName: string | null;
|
|
382
400
|
/**
|
|
383
401
|
* Provides the set of JS engine resource constraints for this Worker thread.
|
|
384
402
|
* If the `resourceLimits` option was passed to the `Worker` constructor,
|
|
@@ -390,7 +408,7 @@ declare module "worker_threads" {
|
|
|
390
408
|
readonly resourceLimits?: ResourceLimits | undefined;
|
|
391
409
|
/**
|
|
392
410
|
* An object that can be used to query performance information from a worker
|
|
393
|
-
* instance.
|
|
411
|
+
* instance.
|
|
394
412
|
* @since v15.1.0, v14.17.0, v12.22.0
|
|
395
413
|
*/
|
|
396
414
|
readonly performance: WorkerPerformance;
|
|
@@ -405,7 +423,7 @@ declare module "worker_threads" {
|
|
|
405
423
|
* See `port.postMessage()` for more details.
|
|
406
424
|
* @since v10.5.0
|
|
407
425
|
*/
|
|
408
|
-
postMessage(value: any, transferList?: readonly
|
|
426
|
+
postMessage(value: any, transferList?: readonly Transferable[]): void;
|
|
409
427
|
/**
|
|
410
428
|
* Opposite of `unref()`, calling `ref()` on a previously `unref()`ed worker does _not_ let the program exit if it's the only active handle left (the default
|
|
411
429
|
* behavior). If the worker is `ref()`ed, calling `ref()` again has
|
|
@@ -415,7 +433,7 @@ declare module "worker_threads" {
|
|
|
415
433
|
ref(): void;
|
|
416
434
|
/**
|
|
417
435
|
* Calling `unref()` on a worker allows the thread to exit if this is the only
|
|
418
|
-
* active handle in the event system. If the worker is already `unref()`ed calling`unref()` again has no effect.
|
|
436
|
+
* active handle in the event system. If the worker is already `unref()`ed calling `unref()` again has no effect.
|
|
419
437
|
* @since v10.5.0
|
|
420
438
|
*/
|
|
421
439
|
unref(): void;
|
|
@@ -425,6 +443,13 @@ declare module "worker_threads" {
|
|
|
425
443
|
* @since v10.5.0
|
|
426
444
|
*/
|
|
427
445
|
terminate(): Promise<number>;
|
|
446
|
+
/**
|
|
447
|
+
* This method returns a `Promise` that will resolve to an object identical to {@link process.threadCpuUsage()},
|
|
448
|
+
* or reject with an [`ERR_WORKER_NOT_RUNNING`](https://nodejs.org/docs/latest-v24.x/api/errors.html#err_worker_not_running) error if the worker is no longer running.
|
|
449
|
+
* This methods allows the statistics to be observed from outside the actual thread.
|
|
450
|
+
* @since v24.6.0
|
|
451
|
+
*/
|
|
452
|
+
cpuUsage(prev?: NodeJS.CpuUsage): Promise<NodeJS.CpuUsage>;
|
|
428
453
|
/**
|
|
429
454
|
* Returns a readable stream for a V8 snapshot of the current state of the Worker.
|
|
430
455
|
* See `v8.getHeapSnapshot()` for more details.
|
|
@@ -435,49 +460,143 @@ declare module "worker_threads" {
|
|
|
435
460
|
* @return A promise for a Readable Stream containing a V8 heap snapshot
|
|
436
461
|
*/
|
|
437
462
|
getHeapSnapshot(): Promise<Readable>;
|
|
438
|
-
|
|
463
|
+
/**
|
|
464
|
+
* This method returns a `Promise` that will resolve to an object identical to `v8.getHeapStatistics()`,
|
|
465
|
+
* or reject with an `ERR_WORKER_NOT_RUNNING` error if the worker is no longer running.
|
|
466
|
+
* This methods allows the statistics to be observed from outside the actual thread.
|
|
467
|
+
* @since v24.0.0
|
|
468
|
+
*/
|
|
469
|
+
getHeapStatistics(): Promise<HeapInfo>;
|
|
470
|
+
/**
|
|
471
|
+
* Starting a CPU profile then return a Promise that fulfills with an error
|
|
472
|
+
* or an `CPUProfileHandle` object. This API supports `await using` syntax.
|
|
473
|
+
*
|
|
474
|
+
* ```js
|
|
475
|
+
* const { Worker } = require('node:worker_threads');
|
|
476
|
+
*
|
|
477
|
+
* const worker = new Worker(`
|
|
478
|
+
* const { parentPort } = require('worker_threads');
|
|
479
|
+
* parentPort.on('message', () => {});
|
|
480
|
+
* `, { eval: true });
|
|
481
|
+
*
|
|
482
|
+
* worker.on('online', async () => {
|
|
483
|
+
* const handle = await worker.startCpuProfile();
|
|
484
|
+
* const profile = await handle.stop();
|
|
485
|
+
* console.log(profile);
|
|
486
|
+
* worker.terminate();
|
|
487
|
+
* });
|
|
488
|
+
* ```
|
|
489
|
+
*
|
|
490
|
+
* `await using` example.
|
|
491
|
+
*
|
|
492
|
+
* ```js
|
|
493
|
+
* const { Worker } = require('node:worker_threads');
|
|
494
|
+
*
|
|
495
|
+
* const w = new Worker(`
|
|
496
|
+
* const { parentPort } = require('node:worker_threads');
|
|
497
|
+
* parentPort.on('message', () => {});
|
|
498
|
+
* `, { eval: true });
|
|
499
|
+
*
|
|
500
|
+
* w.on('online', async () => {
|
|
501
|
+
* // Stop profile automatically when return and profile will be discarded
|
|
502
|
+
* await using handle = await w.startCpuProfile();
|
|
503
|
+
* });
|
|
504
|
+
* ```
|
|
505
|
+
* @since v24.8.0
|
|
506
|
+
*/
|
|
507
|
+
startCpuProfile(): Promise<CPUProfileHandle>;
|
|
508
|
+
/**
|
|
509
|
+
* Starting a Heap profile then return a Promise that fulfills with an error
|
|
510
|
+
* or an `HeapProfileHandle` object. This API supports `await using` syntax.
|
|
511
|
+
*
|
|
512
|
+
* ```js
|
|
513
|
+
* const { Worker } = require('node:worker_threads');
|
|
514
|
+
*
|
|
515
|
+
* const worker = new Worker(`
|
|
516
|
+
* const { parentPort } = require('worker_threads');
|
|
517
|
+
* parentPort.on('message', () => {});
|
|
518
|
+
* `, { eval: true });
|
|
519
|
+
*
|
|
520
|
+
* worker.on('online', async () => {
|
|
521
|
+
* const handle = await worker.startHeapProfile();
|
|
522
|
+
* const profile = await handle.stop();
|
|
523
|
+
* console.log(profile);
|
|
524
|
+
* worker.terminate();
|
|
525
|
+
* });
|
|
526
|
+
* ```
|
|
527
|
+
*
|
|
528
|
+
* `await using` example.
|
|
529
|
+
*
|
|
530
|
+
* ```js
|
|
531
|
+
* const { Worker } = require('node:worker_threads');
|
|
532
|
+
*
|
|
533
|
+
* const w = new Worker(`
|
|
534
|
+
* const { parentPort } = require('node:worker_threads');
|
|
535
|
+
* parentPort.on('message', () => {});
|
|
536
|
+
* `, { eval: true });
|
|
537
|
+
*
|
|
538
|
+
* w.on('online', async () => {
|
|
539
|
+
* // Stop profile automatically when return and profile will be discarded
|
|
540
|
+
* await using handle = await w.startHeapProfile();
|
|
541
|
+
* });
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
startHeapProfile(): Promise<HeapProfileHandle>;
|
|
545
|
+
/**
|
|
546
|
+
* Calls `worker.terminate()` when the dispose scope is exited.
|
|
547
|
+
*
|
|
548
|
+
* ```js
|
|
549
|
+
* async function example() {
|
|
550
|
+
* await using worker = new Worker('for (;;) {}', { eval: true });
|
|
551
|
+
* // Worker is automatically terminate when the scope is exited.
|
|
552
|
+
* }
|
|
553
|
+
* ```
|
|
554
|
+
* @since v24.2.0
|
|
555
|
+
*/
|
|
556
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
557
|
+
addListener(event: "error", listener: (err: any) => void): this;
|
|
439
558
|
addListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
440
559
|
addListener(event: "message", listener: (value: any) => void): this;
|
|
441
560
|
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
442
561
|
addListener(event: "online", listener: () => void): this;
|
|
443
562
|
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
444
|
-
emit(event: "error", err:
|
|
563
|
+
emit(event: "error", err: any): boolean;
|
|
445
564
|
emit(event: "exit", exitCode: number): boolean;
|
|
446
565
|
emit(event: "message", value: any): boolean;
|
|
447
566
|
emit(event: "messageerror", error: Error): boolean;
|
|
448
567
|
emit(event: "online"): boolean;
|
|
449
568
|
emit(event: string | symbol, ...args: any[]): boolean;
|
|
450
|
-
on(event: "error", listener: (err:
|
|
569
|
+
on(event: "error", listener: (err: any) => void): this;
|
|
451
570
|
on(event: "exit", listener: (exitCode: number) => void): this;
|
|
452
571
|
on(event: "message", listener: (value: any) => void): this;
|
|
453
572
|
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
454
573
|
on(event: "online", listener: () => void): this;
|
|
455
574
|
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
456
|
-
once(event: "error", listener: (err:
|
|
575
|
+
once(event: "error", listener: (err: any) => void): this;
|
|
457
576
|
once(event: "exit", listener: (exitCode: number) => void): this;
|
|
458
577
|
once(event: "message", listener: (value: any) => void): this;
|
|
459
578
|
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
460
579
|
once(event: "online", listener: () => void): this;
|
|
461
580
|
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
462
|
-
prependListener(event: "error", listener: (err:
|
|
581
|
+
prependListener(event: "error", listener: (err: any) => void): this;
|
|
463
582
|
prependListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
464
583
|
prependListener(event: "message", listener: (value: any) => void): this;
|
|
465
584
|
prependListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
466
585
|
prependListener(event: "online", listener: () => void): this;
|
|
467
586
|
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
468
|
-
prependOnceListener(event: "error", listener: (err:
|
|
587
|
+
prependOnceListener(event: "error", listener: (err: any) => void): this;
|
|
469
588
|
prependOnceListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
470
589
|
prependOnceListener(event: "message", listener: (value: any) => void): this;
|
|
471
590
|
prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
472
591
|
prependOnceListener(event: "online", listener: () => void): this;
|
|
473
592
|
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
474
|
-
removeListener(event: "error", listener: (err:
|
|
593
|
+
removeListener(event: "error", listener: (err: any) => void): this;
|
|
475
594
|
removeListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
476
595
|
removeListener(event: "message", listener: (value: any) => void): this;
|
|
477
596
|
removeListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
478
597
|
removeListener(event: "online", listener: () => void): this;
|
|
479
598
|
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
480
|
-
off(event: "error", listener: (err:
|
|
599
|
+
off(event: "error", listener: (err: any) => void): this;
|
|
481
600
|
off(event: "exit", listener: (exitCode: number) => void): this;
|
|
482
601
|
off(event: "message", listener: (value: any) => void): this;
|
|
483
602
|
off(event: "messageerror", listener: (error: Error) => void): this;
|
|
@@ -492,11 +611,11 @@ declare module "worker_threads" {
|
|
|
492
611
|
* ```js
|
|
493
612
|
* 'use strict';
|
|
494
613
|
*
|
|
495
|
-
*
|
|
614
|
+
* import {
|
|
496
615
|
* isMainThread,
|
|
497
616
|
* BroadcastChannel,
|
|
498
617
|
* Worker,
|
|
499
|
-
* }
|
|
618
|
+
* } from 'node:worker_threads';
|
|
500
619
|
*
|
|
501
620
|
* const bc = new BroadcastChannel('hello');
|
|
502
621
|
*
|
|
@@ -515,18 +634,18 @@ declare module "worker_threads" {
|
|
|
515
634
|
* ```
|
|
516
635
|
* @since v15.4.0
|
|
517
636
|
*/
|
|
518
|
-
class BroadcastChannel {
|
|
637
|
+
class BroadcastChannel extends EventTarget {
|
|
519
638
|
readonly name: string;
|
|
520
639
|
/**
|
|
521
640
|
* Invoked with a single \`MessageEvent\` argument when a message is received.
|
|
522
641
|
* @since v15.4.0
|
|
523
642
|
*/
|
|
524
|
-
onmessage: (message:
|
|
643
|
+
onmessage: (message: MessageEvent) => void;
|
|
525
644
|
/**
|
|
526
645
|
* Invoked with a received message cannot be deserialized.
|
|
527
646
|
* @since v15.4.0
|
|
528
647
|
*/
|
|
529
|
-
onmessageerror: (message:
|
|
648
|
+
onmessageerror: (message: MessageEvent) => void;
|
|
530
649
|
constructor(name: string);
|
|
531
650
|
/**
|
|
532
651
|
* Closes the `BroadcastChannel` connection.
|
|
@@ -539,9 +658,38 @@ declare module "worker_threads" {
|
|
|
539
658
|
*/
|
|
540
659
|
postMessage(message: unknown): void;
|
|
541
660
|
}
|
|
661
|
+
interface Lock {
|
|
662
|
+
readonly mode: LockMode;
|
|
663
|
+
readonly name: string;
|
|
664
|
+
}
|
|
665
|
+
interface LockGrantedCallback<T> {
|
|
666
|
+
(lock: Lock | null): T;
|
|
667
|
+
}
|
|
668
|
+
interface LockInfo {
|
|
669
|
+
clientId: string;
|
|
670
|
+
mode: LockMode;
|
|
671
|
+
name: string;
|
|
672
|
+
}
|
|
673
|
+
interface LockManager {
|
|
674
|
+
query(): Promise<LockManagerSnapshot>;
|
|
675
|
+
request<T>(name: string, callback: LockGrantedCallback<T>): Promise<Awaited<T>>;
|
|
676
|
+
request<T>(name: string, options: LockOptions, callback: LockGrantedCallback<T>): Promise<Awaited<T>>;
|
|
677
|
+
}
|
|
678
|
+
interface LockManagerSnapshot {
|
|
679
|
+
held: LockInfo[];
|
|
680
|
+
pending: LockInfo[];
|
|
681
|
+
}
|
|
682
|
+
type LockMode = "exclusive" | "shared";
|
|
683
|
+
interface LockOptions {
|
|
684
|
+
ifAvailable?: boolean;
|
|
685
|
+
mode?: LockMode;
|
|
686
|
+
signal?: AbortSignal;
|
|
687
|
+
steal?: boolean;
|
|
688
|
+
}
|
|
689
|
+
var locks: LockManager;
|
|
542
690
|
/**
|
|
543
691
|
* Mark an object as not transferable. If `object` occurs in the transfer list of
|
|
544
|
-
* a
|
|
692
|
+
* a {@link MessagePort.postMessage port.postMessage()} call, it is ignored.
|
|
545
693
|
*
|
|
546
694
|
* In particular, this makes sense for objects that can be cloned, rather than
|
|
547
695
|
* transferred, and which are used by other objects on the sending side.
|
|
@@ -550,7 +698,7 @@ declare module "worker_threads" {
|
|
|
550
698
|
* This operation cannot be undone.
|
|
551
699
|
*
|
|
552
700
|
* ```js
|
|
553
|
-
*
|
|
701
|
+
* import { MessageChannel, markAsUntransferable } from 'node:worker_threads';
|
|
554
702
|
*
|
|
555
703
|
* const pooledBuffer = new ArrayBuffer(8);
|
|
556
704
|
* const typedArray1 = new Uint8Array(pooledBuffer);
|
|
@@ -574,7 +722,40 @@ declare module "worker_threads" {
|
|
|
574
722
|
*/
|
|
575
723
|
function markAsUntransferable(object: object): void;
|
|
576
724
|
/**
|
|
577
|
-
*
|
|
725
|
+
* Check if an object is marked as not transferable with
|
|
726
|
+
* {@link markAsUntransferable}.
|
|
727
|
+
* @since v21.0.0
|
|
728
|
+
*/
|
|
729
|
+
function isMarkedAsUntransferable(object: object): boolean;
|
|
730
|
+
/**
|
|
731
|
+
* Mark an object as not cloneable. If `object` is used as `message` in
|
|
732
|
+
* a `port.postMessage()` call, an error is thrown. This is a no-op if `object` is a
|
|
733
|
+
* primitive value.
|
|
734
|
+
*
|
|
735
|
+
* This has no effect on `ArrayBuffer`, or any `Buffer` like objects.
|
|
736
|
+
*
|
|
737
|
+
* This operation cannot be undone.
|
|
738
|
+
*
|
|
739
|
+
* ```js
|
|
740
|
+
* const { markAsUncloneable } = require('node:worker_threads');
|
|
741
|
+
*
|
|
742
|
+
* const anyObject = { foo: 'bar' };
|
|
743
|
+
* markAsUncloneable(anyObject);
|
|
744
|
+
* const { port1 } = new MessageChannel();
|
|
745
|
+
* try {
|
|
746
|
+
* // This will throw an error, because anyObject is not cloneable.
|
|
747
|
+
* port1.postMessage(anyObject)
|
|
748
|
+
* } catch (error) {
|
|
749
|
+
* // error.name === 'DataCloneError'
|
|
750
|
+
* }
|
|
751
|
+
* ```
|
|
752
|
+
*
|
|
753
|
+
* There is no equivalent to this API in browsers.
|
|
754
|
+
* @since v22.10.0
|
|
755
|
+
*/
|
|
756
|
+
function markAsUncloneable(object: object): void;
|
|
757
|
+
/**
|
|
758
|
+
* Transfer a `MessagePort` to a different `vm` Context. The original `port` object is rendered unusable, and the returned `MessagePort` instance
|
|
578
759
|
* takes its place.
|
|
579
760
|
*
|
|
580
761
|
* The returned `MessagePort` is an object in the target context and
|
|
@@ -592,10 +773,10 @@ declare module "worker_threads" {
|
|
|
592
773
|
function moveMessagePortToContext(port: MessagePort, contextifiedSandbox: Context): MessagePort;
|
|
593
774
|
/**
|
|
594
775
|
* Receive a single message from a given `MessagePort`. If no message is available,`undefined` is returned, otherwise an object with a single `message` property
|
|
595
|
-
* that contains the message payload, corresponding to the oldest message in the`MessagePort`'s queue.
|
|
776
|
+
* that contains the message payload, corresponding to the oldest message in the `MessagePort`'s queue.
|
|
596
777
|
*
|
|
597
778
|
* ```js
|
|
598
|
-
*
|
|
779
|
+
* import { MessageChannel, receiveMessageOnPort } from 'node:worker_threads';
|
|
599
780
|
* const { port1, port2 } = new MessageChannel();
|
|
600
781
|
* port1.postMessage({ hello: 'world' });
|
|
601
782
|
*
|
|
@@ -605,7 +786,7 @@ declare module "worker_threads" {
|
|
|
605
786
|
* // Prints: undefined
|
|
606
787
|
* ```
|
|
607
788
|
*
|
|
608
|
-
* When this function is used, no `'message'` event is emitted and the`onmessage` listener is not invoked.
|
|
789
|
+
* When this function is used, no `'message'` event is emitted and the `onmessage` listener is not invoked.
|
|
609
790
|
* @since v12.3.0
|
|
610
791
|
*/
|
|
611
792
|
function receiveMessageOnPort(port: MessagePort):
|
|
@@ -621,32 +802,50 @@ declare module "worker_threads" {
|
|
|
621
802
|
* automatically.
|
|
622
803
|
*
|
|
623
804
|
* ```js
|
|
624
|
-
*
|
|
805
|
+
* import {
|
|
625
806
|
* Worker,
|
|
626
807
|
* isMainThread,
|
|
627
808
|
* setEnvironmentData,
|
|
628
809
|
* getEnvironmentData,
|
|
629
|
-
* }
|
|
810
|
+
* } from 'node:worker_threads';
|
|
630
811
|
*
|
|
631
812
|
* if (isMainThread) {
|
|
632
813
|
* setEnvironmentData('Hello', 'World!');
|
|
633
|
-
* const worker = new Worker(
|
|
814
|
+
* const worker = new Worker(new URL(import.meta.url));
|
|
634
815
|
* } else {
|
|
635
816
|
* console.log(getEnvironmentData('Hello')); // Prints 'World!'.
|
|
636
817
|
* }
|
|
637
818
|
* ```
|
|
638
819
|
* @since v15.12.0, v14.18.0
|
|
639
|
-
* @param key Any arbitrary, cloneable JavaScript value that can be used as a {Map} key.
|
|
820
|
+
* @param key Any arbitrary, cloneable JavaScript value that can be used as a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Map} key.
|
|
640
821
|
*/
|
|
641
822
|
function getEnvironmentData(key: Serializable): Serializable;
|
|
642
823
|
/**
|
|
643
|
-
* The `worker.setEnvironmentData()` API sets the content of`worker.getEnvironmentData()` in the current thread and all new `Worker`instances spawned from the current context.
|
|
824
|
+
* The `worker.setEnvironmentData()` API sets the content of `worker.getEnvironmentData()` in the current thread and all new `Worker` instances spawned from the current context.
|
|
644
825
|
* @since v15.12.0, v14.18.0
|
|
645
826
|
* @param key Any arbitrary, cloneable JavaScript value that can be used as a {Map} key.
|
|
646
827
|
* @param value Any arbitrary, cloneable JavaScript value that will be cloned and passed automatically to all new `Worker` instances. If `value` is passed as `undefined`, any previously set value
|
|
647
828
|
* for the `key` will be deleted.
|
|
648
829
|
*/
|
|
649
|
-
function setEnvironmentData(key: Serializable, value
|
|
830
|
+
function setEnvironmentData(key: Serializable, value?: Serializable): void;
|
|
831
|
+
/**
|
|
832
|
+
* Sends a value to another worker, identified by its thread ID.
|
|
833
|
+
* @param threadId The target thread ID. If the thread ID is invalid, a `ERR_WORKER_MESSAGING_FAILED` error will be thrown.
|
|
834
|
+
* If the target thread ID is the current thread ID, a `ERR_WORKER_MESSAGING_SAME_THREAD` error will be thrown.
|
|
835
|
+
* @param value The value to send.
|
|
836
|
+
* @param transferList If one or more `MessagePort`-like objects are passed in value, a `transferList` is required for those items
|
|
837
|
+
* or `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST` is thrown. See `port.postMessage()` for more information.
|
|
838
|
+
* @param timeout Time to wait for the message to be delivered in milliseconds. By default it's `undefined`, which means wait forever.
|
|
839
|
+
* If the operation times out, a `ERR_WORKER_MESSAGING_TIMEOUT` error is thrown.
|
|
840
|
+
* @since v22.5.0
|
|
841
|
+
*/
|
|
842
|
+
function postMessageToThread(threadId: number, value: any, timeout?: number): Promise<void>;
|
|
843
|
+
function postMessageToThread(
|
|
844
|
+
threadId: number,
|
|
845
|
+
value: any,
|
|
846
|
+
transferList: readonly Transferable[],
|
|
847
|
+
timeout?: number,
|
|
848
|
+
): Promise<void>;
|
|
650
849
|
|
|
651
850
|
import {
|
|
652
851
|
BroadcastChannel as _BroadcastChannel,
|
|
@@ -654,8 +853,12 @@ declare module "worker_threads" {
|
|
|
654
853
|
MessagePort as _MessagePort,
|
|
655
854
|
} from "worker_threads";
|
|
656
855
|
global {
|
|
856
|
+
function structuredClone<T>(
|
|
857
|
+
value: T,
|
|
858
|
+
options?: { transfer?: Transferable[] },
|
|
859
|
+
): T;
|
|
657
860
|
/**
|
|
658
|
-
* `BroadcastChannel` class is a global reference for `
|
|
861
|
+
* `BroadcastChannel` class is a global reference for `import { BroadcastChannel } from 'worker_threads'`
|
|
659
862
|
* https://nodejs.org/api/globals.html#broadcastchannel
|
|
660
863
|
* @since v18.0.0
|
|
661
864
|
*/
|
|
@@ -665,7 +868,7 @@ declare module "worker_threads" {
|
|
|
665
868
|
} ? T
|
|
666
869
|
: typeof _BroadcastChannel;
|
|
667
870
|
/**
|
|
668
|
-
* `MessageChannel` class is a global reference for `
|
|
871
|
+
* `MessageChannel` class is a global reference for `import { MessageChannel } from 'worker_threads'`
|
|
669
872
|
* https://nodejs.org/api/globals.html#messagechannel
|
|
670
873
|
* @since v15.0.0
|
|
671
874
|
*/
|
|
@@ -675,7 +878,7 @@ declare module "worker_threads" {
|
|
|
675
878
|
} ? T
|
|
676
879
|
: typeof _MessageChannel;
|
|
677
880
|
/**
|
|
678
|
-
* `MessagePort` class is a global reference for `
|
|
881
|
+
* `MessagePort` class is a global reference for `import { MessagePort } from 'worker_threads'`
|
|
679
882
|
* https://nodejs.org/api/globals.html#messageport
|
|
680
883
|
* @since v15.0.0
|
|
681
884
|
*/
|