aws-delivlib 15.4.1 → 15.4.2
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/lib/custom-resource-handlers/src/certificate-signing-request.tsbuildinfo +1 -1
- package/lib/custom-resource-handlers/src/pgp-secret.tsbuildinfo +1 -1
- package/lib/custom-resource-handlers/src/private-key.tsbuildinfo +1 -1
- package/lib/package-integrity/handler/validate.bundle.js +11361 -9248
- package/lib/publishing/github/node_modules/.yarn-integrity +5 -5
- package/lib/publishing/github/node_modules/@types/aws-lambda/README.md +1 -1
- package/lib/publishing/github/node_modules/@types/aws-lambda/package.json +2 -2
- package/lib/publishing/github/node_modules/@types/aws-lambda/trigger/api-gateway-proxy.d.ts +2 -2
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/README.md +3 -3
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/assert/strict.d.ts +13 -56
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/assert.d.ts +189 -190
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/async_hooks.d.ts +151 -43
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/buffer.buffer.d.ts +12 -13
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/buffer.d.ts +103 -237
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/child_process.d.ts +40 -155
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/cluster.d.ts +238 -384
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/console.d.ts +45 -404
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/constants.d.ts +3 -10
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/crypto.d.ts +1019 -1600
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/dgram.d.ts +133 -81
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/diagnostics_channel.d.ts +277 -59
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/dns/promises.d.ts +9 -15
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/dns.d.ts +136 -183
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/domain.d.ts +12 -32
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/events.d.ts +872 -840
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ffi.d.ts +500 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/fs/promises.d.ts +256 -85
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/fs.d.ts +865 -525
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/globals.d.ts +12 -34
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/globals.typedarray.d.ts +63 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/http.d.ts +433 -312
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/http2.d.ts +548 -893
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/https.d.ts +64 -243
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/index.d.ts +25 -7
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/inspector/promises.d.ts +35 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/inspector.d.ts +70 -58
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/inspector.generated.d.ts +764 -410
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/module.d.ts +54 -219
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/net.d.ts +224 -226
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/os.d.ts +41 -49
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/package.json +13 -18
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/path/posix.d.ts +8 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/path/win32.d.ts +8 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/path.d.ts +119 -141
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/perf_hooks.d.ts +339 -690
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/process.d.ts +390 -205
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/punycode.d.ts +3 -31
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/querystring.d.ts +3 -16
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/quic.d.ts +2191 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/readline/promises.d.ts +3 -6
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/readline.d.ts +66 -152
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/repl.d.ts +101 -109
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/sea.d.ts +1 -116
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/sqlite.d.ts +486 -68
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/stream/consumers.d.ts +91 -15
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/stream/iter.d.ts +449 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/stream/promises.d.ts +136 -15
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/stream/web.d.ts +197 -454
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/stream.d.ts +603 -491
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/string_decoder.d.ts +3 -43
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/test/reporters.d.ts +60 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/test.d.ts +585 -292
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/timers/promises.d.ts +3 -18
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/timers.d.ts +3 -141
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/tls.d.ts +180 -267
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/trace_events.d.ts +3 -97
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +7 -8
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +2 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.6/index.d.ts +26 -6
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.7/index.d.ts +118 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/tty.d.ts +61 -43
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/url.d.ts +156 -584
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/util/types.d.ts +558 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/util.d.ts +173 -1099
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/v8.d.ts +175 -36
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/vfs.d.ts +211 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/vm.d.ts +293 -209
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/wasi.d.ts +24 -74
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/abortcontroller.d.ts +27 -2
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/blob.d.ts +23 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/console.d.ts +9 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/crypto.d.ts +39 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/domexception.d.ts +15 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/encoding.d.ts +11 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/events.d.ts +9 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/fetch.d.ts +14 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/importmeta.d.ts +13 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/messaging.d.ts +23 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/navigator.d.ts +3 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/performance.d.ts +45 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/streams.d.ts +97 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/timers.d.ts +44 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/url.d.ts +24 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/worker_threads.d.ts +260 -407
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/zlib/iter.d.ts +131 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/zlib.d.ts +782 -165
- package/lib/publishing/github/node_modules/semver/classes/range.js +2 -2
- package/lib/publishing/github/node_modules/semver/internal/constants.js +30 -0
- package/lib/publishing/github/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
- package/lib/publishing/github/node_modules/semver/package.json +1 -1
- package/lib/publishing/github/node_modules/undici-types/agent.d.ts +12 -13
- package/lib/publishing/github/node_modules/undici-types/api.d.ts +26 -26
- package/lib/publishing/github/node_modules/undici-types/balanced-pool.d.ts +13 -12
- package/lib/publishing/github/node_modules/undici-types/cache-interceptor.d.ts +179 -0
- package/lib/publishing/github/node_modules/undici-types/client-stats.d.ts +15 -0
- package/lib/publishing/github/node_modules/undici-types/client.d.ts +63 -37
- package/lib/publishing/github/node_modules/undici-types/connector.d.ts +5 -2
- package/lib/publishing/github/node_modules/undici-types/cookies.d.ts +3 -1
- package/lib/publishing/github/node_modules/undici-types/diagnostics-channel.d.ts +18 -10
- package/lib/publishing/github/node_modules/undici-types/dispatcher.d.ts +136 -139
- package/lib/publishing/github/node_modules/undici-types/dispatcher1-wrapper.d.ts +7 -0
- package/lib/publishing/github/node_modules/undici-types/env-http-proxy-agent.d.ts +4 -3
- package/lib/publishing/github/node_modules/undici-types/errors.d.ts +92 -54
- package/lib/publishing/github/node_modules/undici-types/eventsource.d.ts +9 -4
- package/lib/publishing/github/node_modules/undici-types/fetch.d.ts +51 -25
- package/lib/publishing/github/node_modules/undici-types/formdata.d.ts +7 -7
- package/lib/publishing/github/node_modules/undici-types/global-dispatcher.d.ts +4 -4
- package/lib/publishing/github/node_modules/undici-types/global-origin.d.ts +5 -5
- package/lib/publishing/github/node_modules/undici-types/h2c-client.d.ts +73 -0
- package/lib/publishing/github/node_modules/undici-types/handlers.d.ts +10 -9
- package/lib/publishing/github/node_modules/undici-types/header.d.ts +162 -1
- package/lib/publishing/github/node_modules/undici-types/index.d.ts +69 -47
- package/lib/publishing/github/node_modules/undici-types/interceptors.d.ts +72 -9
- package/lib/publishing/github/node_modules/undici-types/mock-agent.d.ts +36 -18
- package/lib/publishing/github/node_modules/undici-types/mock-call-history.d.ts +111 -0
- package/lib/publishing/github/node_modules/undici-types/mock-client.d.ts +6 -4
- package/lib/publishing/github/node_modules/undici-types/mock-errors.d.ts +3 -3
- package/lib/publishing/github/node_modules/undici-types/mock-interceptor.d.ts +26 -21
- package/lib/publishing/github/node_modules/undici-types/mock-pool.d.ts +6 -4
- package/lib/publishing/github/node_modules/undici-types/package.json +1 -1
- package/lib/publishing/github/node_modules/undici-types/patch.d.ts +0 -4
- package/lib/publishing/github/node_modules/undici-types/pool-stats.d.ts +8 -8
- package/lib/publishing/github/node_modules/undici-types/pool.d.ts +14 -14
- package/lib/publishing/github/node_modules/undici-types/proxy-agent.d.ts +14 -6
- package/lib/publishing/github/node_modules/undici-types/readable.d.ts +19 -16
- package/lib/publishing/github/node_modules/undici-types/retry-agent.d.ts +1 -1
- package/lib/publishing/github/node_modules/undici-types/retry-handler.d.ts +19 -10
- package/lib/publishing/github/node_modules/undici-types/round-robin-pool.d.ts +39 -0
- package/lib/publishing/github/node_modules/undici-types/snapshot-agent.d.ts +113 -0
- package/lib/publishing/github/node_modules/undici-types/socks5-proxy-agent.d.ts +25 -0
- package/lib/publishing/github/node_modules/undici-types/util.d.ts +3 -3
- package/lib/publishing/github/node_modules/undici-types/utility.d.ts +7 -0
- package/lib/publishing/github/node_modules/undici-types/webidl.d.ts +148 -30
- package/lib/publishing/github/node_modules/undici-types/websocket.d.ts +48 -10
- package/lib/shellable.d.ts +7 -3
- package/lib/shellable.js +37 -27
- package/package.json +11 -11
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/compatibility/disposable.d.ts +0 -14
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/compatibility/index.d.ts +0 -9
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/compatibility/indexable.d.ts +0 -20
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/compatibility/iterators.d.ts +0 -20
- package/lib/publishing/github/node_modules/undici-types/file.d.ts +0 -39
- package/lib/publishing/github/node_modules/undici-types/filereader.d.ts +0 -54
|
@@ -1,68 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* Workers (threads) are useful for performing CPU-intensive JavaScript operations.
|
|
10
|
-
* They do not help much with I/O-intensive work. The Node.js built-in
|
|
11
|
-
* asynchronous I/O operations are more efficient than Workers can be.
|
|
12
|
-
*
|
|
13
|
-
* Unlike `child_process` or `cluster`, `worker_threads` can share memory. They do
|
|
14
|
-
* so by transferring `ArrayBuffer` instances or sharing `SharedArrayBuffer` instances.
|
|
15
|
-
*
|
|
16
|
-
* ```js
|
|
17
|
-
* import {
|
|
18
|
-
* Worker,
|
|
19
|
-
* isMainThread,
|
|
20
|
-
* parentPort,
|
|
21
|
-
* workerData,
|
|
22
|
-
* } from 'node:worker_threads';
|
|
23
|
-
*
|
|
24
|
-
* if (!isMainThread) {
|
|
25
|
-
* const { parse } = await import('some-js-parsing-library');
|
|
26
|
-
* const script = workerData;
|
|
27
|
-
* parentPort.postMessage(parse(script));
|
|
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.on('error', reject);
|
|
37
|
-
* worker.on('exit', (code) => {
|
|
38
|
-
* if (code !== 0)
|
|
39
|
-
* reject(new Error(`Worker stopped with exit code ${code}`));
|
|
40
|
-
* });
|
|
41
|
-
* });
|
|
42
|
-
* };
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* The above example spawns a Worker thread for each `parseJSAsync()` call. In
|
|
46
|
-
* practice, use a pool of Workers for these kinds of tasks. Otherwise, the
|
|
47
|
-
* overhead of creating Workers would likely exceed their benefit.
|
|
48
|
-
*
|
|
49
|
-
* When implementing a worker pool, use the `AsyncResource` API to inform
|
|
50
|
-
* diagnostic tools (e.g. to provide asynchronous stack traces) about the
|
|
51
|
-
* correlation between tasks and their outcomes. See `"Using AsyncResource for a Worker thread pool"` in the `async_hooks` documentation for an example implementation.
|
|
52
|
-
*
|
|
53
|
-
* Worker threads inherit non-process-specific options by default. Refer to `Worker constructor options` to know how to customize worker thread options,
|
|
54
|
-
* specifically `argv` and `execArgv` options.
|
|
55
|
-
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/worker_threads.js)
|
|
56
|
-
*/
|
|
57
|
-
declare module "worker_threads" {
|
|
58
|
-
import { Context } from "node:vm";
|
|
59
|
-
import { EventEmitter, NodeEventTarget } from "node:events";
|
|
60
|
-
import { EventLoopUtilityFunction } from "node:perf_hooks";
|
|
1
|
+
declare module "node:worker_threads" {
|
|
2
|
+
import {
|
|
3
|
+
EventEmitter,
|
|
4
|
+
InternalEventEmitter,
|
|
5
|
+
InternalEventTargetEventProperties,
|
|
6
|
+
NodeEventTarget,
|
|
7
|
+
} from "node:events";
|
|
61
8
|
import { FileHandle } from "node:fs/promises";
|
|
9
|
+
import { Server, Socket } from "node:net";
|
|
10
|
+
import { Performance } from "node:perf_hooks";
|
|
62
11
|
import { Readable, Writable } from "node:stream";
|
|
63
12
|
import { ReadableStream, TransformStream, WritableStream } from "node:stream/web";
|
|
64
13
|
import { URL } from "node:url";
|
|
65
|
-
import { HeapInfo } from "node:v8";
|
|
14
|
+
import { CPUProfileHandle, CPUProfileOptions, HeapInfo, HeapProfileHandle, HeapProfileOptions } from "node:v8";
|
|
15
|
+
import { Context } from "node:vm";
|
|
66
16
|
import { MessageEvent } from "undici-types";
|
|
67
17
|
const isInternalThread: boolean;
|
|
68
18
|
const isMainThread: boolean;
|
|
@@ -72,185 +22,7 @@ declare module "worker_threads" {
|
|
|
72
22
|
const threadId: number;
|
|
73
23
|
const threadName: string | null;
|
|
74
24
|
const workerData: any;
|
|
75
|
-
|
|
76
|
-
* Instances of the `worker.MessageChannel` class represent an asynchronous,
|
|
77
|
-
* two-way communications channel.
|
|
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.
|
|
79
|
-
*
|
|
80
|
-
* ```js
|
|
81
|
-
* import { MessageChannel } from 'node:worker_threads';
|
|
82
|
-
*
|
|
83
|
-
* const { port1, port2 } = new MessageChannel();
|
|
84
|
-
* port1.on('message', (message) => console.log('received', message));
|
|
85
|
-
* port2.postMessage({ foo: 'bar' });
|
|
86
|
-
* // Prints: received { foo: 'bar' } from the `port1.on('message')` listener
|
|
87
|
-
* ```
|
|
88
|
-
* @since v10.5.0
|
|
89
|
-
*/
|
|
90
|
-
class MessageChannel {
|
|
91
|
-
readonly port1: MessagePort;
|
|
92
|
-
readonly port2: MessagePort;
|
|
93
|
-
}
|
|
94
|
-
interface WorkerPerformance {
|
|
95
|
-
eventLoopUtilization: EventLoopUtilityFunction;
|
|
96
|
-
}
|
|
97
|
-
type Transferable =
|
|
98
|
-
| ArrayBuffer
|
|
99
|
-
| MessagePort
|
|
100
|
-
| AbortSignal
|
|
101
|
-
| FileHandle
|
|
102
|
-
| ReadableStream
|
|
103
|
-
| WritableStream
|
|
104
|
-
| TransformStream;
|
|
105
|
-
/** @deprecated Use `import { Transferable } from "node:worker_threads"` instead. */
|
|
106
|
-
type TransferListItem = Transferable;
|
|
107
|
-
/**
|
|
108
|
-
* Instances of the `worker.MessagePort` class represent one end of an
|
|
109
|
-
* asynchronous, two-way communications channel. It can be used to transfer
|
|
110
|
-
* structured data, memory regions and other `MessagePort`s between different `Worker`s.
|
|
111
|
-
*
|
|
112
|
-
* This implementation matches [browser `MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort) s.
|
|
113
|
-
* @since v10.5.0
|
|
114
|
-
*/
|
|
115
|
-
class MessagePort implements EventTarget {
|
|
116
|
-
/**
|
|
117
|
-
* Disables further sending of messages on either side of the connection.
|
|
118
|
-
* This method can be called when no further communication will happen over this `MessagePort`.
|
|
119
|
-
*
|
|
120
|
-
* The `'close' event` is emitted on both `MessagePort` instances that
|
|
121
|
-
* are part of the channel.
|
|
122
|
-
* @since v10.5.0
|
|
123
|
-
*/
|
|
124
|
-
close(): void;
|
|
125
|
-
/**
|
|
126
|
-
* Sends a JavaScript value to the receiving side of this channel. `value` is transferred in a way which is compatible with
|
|
127
|
-
* the [HTML structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
|
|
128
|
-
*
|
|
129
|
-
* In particular, the significant differences to `JSON` are:
|
|
130
|
-
*
|
|
131
|
-
* * `value` may contain circular references.
|
|
132
|
-
* * `value` may contain instances of builtin JS types such as `RegExp`s, `BigInt`s, `Map`s, `Set`s, etc.
|
|
133
|
-
* * `value` may contain typed arrays, both using `ArrayBuffer`s
|
|
134
|
-
* and `SharedArrayBuffer`s.
|
|
135
|
-
* * `value` may contain [`WebAssembly.Module`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) instances.
|
|
136
|
-
* * `value` may not contain native (C++-backed) objects other than:
|
|
137
|
-
*
|
|
138
|
-
* ```js
|
|
139
|
-
* import { MessageChannel } from 'node:worker_threads';
|
|
140
|
-
* const { port1, port2 } = new MessageChannel();
|
|
141
|
-
*
|
|
142
|
-
* port1.on('message', (message) => console.log(message));
|
|
143
|
-
*
|
|
144
|
-
* const circularData = {};
|
|
145
|
-
* circularData.foo = circularData;
|
|
146
|
-
* // Prints: { foo: [Circular] }
|
|
147
|
-
* port2.postMessage(circularData);
|
|
148
|
-
* ```
|
|
149
|
-
*
|
|
150
|
-
* `transferList` may be a list of [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), `MessagePort`, and `FileHandle` objects.
|
|
151
|
-
* After transferring, they are not usable on the sending side of the channel
|
|
152
|
-
* anymore (even if they are not contained in `value`). Unlike with `child processes`, transferring handles such as network sockets is currently
|
|
153
|
-
* not supported.
|
|
154
|
-
*
|
|
155
|
-
* If `value` contains [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances, those are accessible
|
|
156
|
-
* from either thread. They cannot be listed in `transferList`.
|
|
157
|
-
*
|
|
158
|
-
* `value` may still contain `ArrayBuffer` instances that are not in `transferList`; in that case, the underlying memory is copied rather than moved.
|
|
159
|
-
*
|
|
160
|
-
* ```js
|
|
161
|
-
* import { MessageChannel } from 'node:worker_threads';
|
|
162
|
-
* const { port1, port2 } = new MessageChannel();
|
|
163
|
-
*
|
|
164
|
-
* port1.on('message', (message) => console.log(message));
|
|
165
|
-
*
|
|
166
|
-
* const uint8Array = new Uint8Array([ 1, 2, 3, 4 ]);
|
|
167
|
-
* // This posts a copy of `uint8Array`:
|
|
168
|
-
* port2.postMessage(uint8Array);
|
|
169
|
-
* // This does not copy data, but renders `uint8Array` unusable:
|
|
170
|
-
* port2.postMessage(uint8Array, [ uint8Array.buffer ]);
|
|
171
|
-
*
|
|
172
|
-
* // The memory for the `sharedUint8Array` is accessible from both the
|
|
173
|
-
* // original and the copy received by `.on('message')`:
|
|
174
|
-
* const sharedUint8Array = new Uint8Array(new SharedArrayBuffer(4));
|
|
175
|
-
* port2.postMessage(sharedUint8Array);
|
|
176
|
-
*
|
|
177
|
-
* // This transfers a freshly created message port to the receiver.
|
|
178
|
-
* // This can be used, for example, to create communication channels between
|
|
179
|
-
* // multiple `Worker` threads that are children of the same parent thread.
|
|
180
|
-
* const otherChannel = new MessageChannel();
|
|
181
|
-
* port2.postMessage({ port: otherChannel.port1 }, [ otherChannel.port1 ]);
|
|
182
|
-
* ```
|
|
183
|
-
*
|
|
184
|
-
* The message object is cloned immediately, and can be modified after
|
|
185
|
-
* posting without having side effects.
|
|
186
|
-
*
|
|
187
|
-
* For more information on the serialization and deserialization mechanisms
|
|
188
|
-
* behind this API, see the `serialization API of the node:v8 module`.
|
|
189
|
-
* @since v10.5.0
|
|
190
|
-
*/
|
|
191
|
-
postMessage(value: any, transferList?: readonly Transferable[]): void;
|
|
192
|
-
/**
|
|
193
|
-
* If true, the `MessagePort` object will keep the Node.js event loop active.
|
|
194
|
-
* @since v18.1.0, v16.17.0
|
|
195
|
-
*/
|
|
196
|
-
hasRef(): boolean;
|
|
197
|
-
/**
|
|
198
|
-
* 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
|
|
199
|
-
* behavior). If the port is `ref()`ed, calling `ref()` again has no effect.
|
|
200
|
-
*
|
|
201
|
-
* If listeners are attached or removed using `.on('message')`, the port
|
|
202
|
-
* is `ref()`ed and `unref()`ed automatically depending on whether
|
|
203
|
-
* listeners for the event exist.
|
|
204
|
-
* @since v10.5.0
|
|
205
|
-
*/
|
|
206
|
-
ref(): void;
|
|
207
|
-
/**
|
|
208
|
-
* Calling `unref()` on a port allows the thread to exit if this is the only
|
|
209
|
-
* active handle in the event system. If the port is already `unref()`ed calling `unref()` again has no effect.
|
|
210
|
-
*
|
|
211
|
-
* If listeners are attached or removed using `.on('message')`, the port is `ref()`ed and `unref()`ed automatically depending on whether
|
|
212
|
-
* listeners for the event exist.
|
|
213
|
-
* @since v10.5.0
|
|
214
|
-
*/
|
|
215
|
-
unref(): void;
|
|
216
|
-
/**
|
|
217
|
-
* Starts receiving messages on this `MessagePort`. When using this port
|
|
218
|
-
* as an event emitter, this is called automatically once `'message'` listeners are attached.
|
|
219
|
-
*
|
|
220
|
-
* This method exists for parity with the Web `MessagePort` API. In Node.js,
|
|
221
|
-
* it is only useful for ignoring messages when no event listener is present.
|
|
222
|
-
* Node.js also diverges in its handling of `.onmessage`. Setting it
|
|
223
|
-
* automatically calls `.start()`, but unsetting it lets messages queue up
|
|
224
|
-
* until a new handler is set or the port is discarded.
|
|
225
|
-
* @since v10.5.0
|
|
226
|
-
*/
|
|
227
|
-
start(): void;
|
|
228
|
-
addListener(event: "close", listener: (ev: Event) => void): this;
|
|
229
|
-
addListener(event: "message", listener: (value: any) => void): this;
|
|
230
|
-
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
231
|
-
addListener(event: string, listener: (arg: any) => void): this;
|
|
232
|
-
emit(event: "close", ev: Event): boolean;
|
|
233
|
-
emit(event: "message", value: any): boolean;
|
|
234
|
-
emit(event: "messageerror", error: Error): boolean;
|
|
235
|
-
emit(event: string, arg: any): boolean;
|
|
236
|
-
off(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
237
|
-
off(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
238
|
-
off(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
239
|
-
off(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
240
|
-
on(event: "close", listener: (ev: Event) => void): this;
|
|
241
|
-
on(event: "message", listener: (value: any) => void): this;
|
|
242
|
-
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
243
|
-
on(event: string, listener: (arg: any) => void): this;
|
|
244
|
-
once(event: "close", listener: (ev: Event) => void): this;
|
|
245
|
-
once(event: "message", listener: (value: any) => void): this;
|
|
246
|
-
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
247
|
-
once(event: string, listener: (arg: any) => void): this;
|
|
248
|
-
removeListener(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
249
|
-
removeListener(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
250
|
-
removeListener(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
251
|
-
removeListener(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
252
|
-
}
|
|
253
|
-
interface MessagePort extends NodeEventTarget {}
|
|
25
|
+
interface WorkerPerformance extends Pick<Performance, "eventLoopUtilization"> {}
|
|
254
26
|
interface WorkerOptions {
|
|
255
27
|
/**
|
|
256
28
|
* List of arguments which would be stringified and appended to
|
|
@@ -301,9 +73,12 @@ declare module "worker_threads" {
|
|
|
301
73
|
*/
|
|
302
74
|
stackSizeMb?: number | undefined;
|
|
303
75
|
}
|
|
304
|
-
interface
|
|
305
|
-
|
|
306
|
-
[
|
|
76
|
+
interface WorkerEventMap {
|
|
77
|
+
"error": [err: unknown];
|
|
78
|
+
"exit": [exitCode: number];
|
|
79
|
+
"message": [value: any];
|
|
80
|
+
"messageerror": [error: Error];
|
|
81
|
+
"online": [];
|
|
307
82
|
}
|
|
308
83
|
/**
|
|
309
84
|
* The `Worker` class represents an independent JavaScript execution thread.
|
|
@@ -369,7 +144,7 @@ declare module "worker_threads" {
|
|
|
369
144
|
* ```
|
|
370
145
|
* @since v10.5.0
|
|
371
146
|
*/
|
|
372
|
-
class Worker
|
|
147
|
+
class Worker implements EventEmitter {
|
|
373
148
|
/**
|
|
374
149
|
* If `stdin: true` was passed to the `Worker` constructor, this is a
|
|
375
150
|
* writable stream. The data written to this stream will be made available in
|
|
@@ -398,8 +173,8 @@ declare module "worker_threads" {
|
|
|
398
173
|
readonly threadId: number;
|
|
399
174
|
/**
|
|
400
175
|
* A string identifier for the referenced thread or null if the thread is not running.
|
|
401
|
-
* Inside the worker thread, it is available as
|
|
402
|
-
* @since
|
|
176
|
+
* Inside the worker thread, it is available as `require('node:worker_threads').threadName`.
|
|
177
|
+
* @since v24.6.0
|
|
403
178
|
*/
|
|
404
179
|
readonly threadName: string | null;
|
|
405
180
|
/**
|
|
@@ -452,7 +227,7 @@ declare module "worker_threads" {
|
|
|
452
227
|
* This method returns a `Promise` that will resolve to an object identical to `process.threadCpuUsage()`,
|
|
453
228
|
* or reject with an `ERR_WORKER_NOT_RUNNING` error if the worker is no longer running.
|
|
454
229
|
* This methods allows the statistics to be observed from outside the actual thread.
|
|
455
|
-
* @since
|
|
230
|
+
* @since v24.6.0
|
|
456
231
|
*/
|
|
457
232
|
cpuUsage(prev?: NodeJS.CpuUsage): Promise<NodeJS.CpuUsage>;
|
|
458
233
|
/**
|
|
@@ -469,14 +244,12 @@ declare module "worker_threads" {
|
|
|
469
244
|
* This method returns a `Promise` that will resolve to an object identical to `v8.getHeapStatistics()`,
|
|
470
245
|
* or reject with an `ERR_WORKER_NOT_RUNNING` error if the worker is no longer running.
|
|
471
246
|
* This methods allows the statistics to be observed from outside the actual thread.
|
|
472
|
-
* @since
|
|
247
|
+
* @since v24.0.0
|
|
473
248
|
*/
|
|
474
249
|
getHeapStatistics(): Promise<HeapInfo>;
|
|
475
250
|
/**
|
|
476
|
-
* Starting a CPU profile
|
|
477
|
-
*
|
|
478
|
-
* stop collecting the profile, then return a Promise that fulfills with an error or the
|
|
479
|
-
* profile data.
|
|
251
|
+
* Starting a CPU profile then return a Promise that fulfills with an error
|
|
252
|
+
* or an `CPUProfileHandle` object. This API supports `await using` syntax.
|
|
480
253
|
*
|
|
481
254
|
* ```js
|
|
482
255
|
* const { Worker } = require('node:worker_threads');
|
|
@@ -487,15 +260,69 @@ declare module "worker_threads" {
|
|
|
487
260
|
* `, { eval: true });
|
|
488
261
|
*
|
|
489
262
|
* worker.on('online', async () => {
|
|
490
|
-
* const handle = await worker.startCpuProfile(
|
|
263
|
+
* const handle = await worker.startCpuProfile({ sampleInterval: 1 });
|
|
491
264
|
* const profile = await handle.stop();
|
|
492
265
|
* console.log(profile);
|
|
493
266
|
* worker.terminate();
|
|
494
267
|
* });
|
|
495
268
|
* ```
|
|
496
|
-
*
|
|
269
|
+
*
|
|
270
|
+
* `await using` example.
|
|
271
|
+
*
|
|
272
|
+
* ```js
|
|
273
|
+
* const { Worker } = require('node:worker_threads');
|
|
274
|
+
*
|
|
275
|
+
* const w = new Worker(`
|
|
276
|
+
* const { parentPort } = require('node:worker_threads');
|
|
277
|
+
* parentPort.on('message', () => {});
|
|
278
|
+
* `, { eval: true });
|
|
279
|
+
*
|
|
280
|
+
* w.on('online', async () => {
|
|
281
|
+
* // Stop profile automatically when return and profile will be discarded
|
|
282
|
+
* await using handle = await w.startCpuProfile();
|
|
283
|
+
* });
|
|
284
|
+
* ```
|
|
285
|
+
* @since v24.8.0
|
|
497
286
|
*/
|
|
498
|
-
startCpuProfile(
|
|
287
|
+
startCpuProfile(options?: CPUProfileOptions): Promise<CPUProfileHandle>;
|
|
288
|
+
/**
|
|
289
|
+
* Starting a Heap profile then return a Promise that fulfills with an error
|
|
290
|
+
* or an `HeapProfileHandle` object. This API supports `await using` syntax.
|
|
291
|
+
*
|
|
292
|
+
* ```js
|
|
293
|
+
* import { Worker } from 'node:worker_threads';
|
|
294
|
+
*
|
|
295
|
+
* const worker = new Worker(`
|
|
296
|
+
* const { parentPort } = require('node:worker_threads');
|
|
297
|
+
* parentPort.on('message', () => {});
|
|
298
|
+
* `, { eval: true });
|
|
299
|
+
*
|
|
300
|
+
* worker.on('online', async () => {
|
|
301
|
+
* const handle = await worker.startHeapProfile();
|
|
302
|
+
* const profile = await handle.stop();
|
|
303
|
+
* console.log(profile);
|
|
304
|
+
* worker.terminate();
|
|
305
|
+
* });
|
|
306
|
+
* ```
|
|
307
|
+
*
|
|
308
|
+
* `await using` example.
|
|
309
|
+
*
|
|
310
|
+
* ```js
|
|
311
|
+
* import { Worker } from 'node:worker_threads';
|
|
312
|
+
*
|
|
313
|
+
* const w = new Worker(`
|
|
314
|
+
* const { parentPort } = require('node:worker_threads');
|
|
315
|
+
* parentPort.on('message', () => {});
|
|
316
|
+
* `, { eval: true });
|
|
317
|
+
*
|
|
318
|
+
* w.on('online', async () => {
|
|
319
|
+
* // Stop profile automatically when return and profile will be discarded
|
|
320
|
+
* await using handle = await w.startHeapProfile();
|
|
321
|
+
* });
|
|
322
|
+
* ```
|
|
323
|
+
* @since v24.9.0
|
|
324
|
+
*/
|
|
325
|
+
startHeapProfile(options?: HeapProfileOptions): Promise<HeapProfileHandle>;
|
|
499
326
|
/**
|
|
500
327
|
* Calls `worker.terminate()` when the dispose scope is exited.
|
|
501
328
|
*
|
|
@@ -505,120 +332,22 @@ declare module "worker_threads" {
|
|
|
505
332
|
* // Worker is automatically terminate when the scope is exited.
|
|
506
333
|
* }
|
|
507
334
|
* ```
|
|
508
|
-
* @since
|
|
335
|
+
* @since v24.2.0
|
|
509
336
|
*/
|
|
510
337
|
[Symbol.asyncDispose](): Promise<void>;
|
|
511
|
-
addListener(event: "error", listener: (err: Error) => void): this;
|
|
512
|
-
addListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
513
|
-
addListener(event: "message", listener: (value: any) => void): this;
|
|
514
|
-
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
515
|
-
addListener(event: "online", listener: () => void): this;
|
|
516
|
-
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
517
|
-
emit(event: "error", err: Error): boolean;
|
|
518
|
-
emit(event: "exit", exitCode: number): boolean;
|
|
519
|
-
emit(event: "message", value: any): boolean;
|
|
520
|
-
emit(event: "messageerror", error: Error): boolean;
|
|
521
|
-
emit(event: "online"): boolean;
|
|
522
|
-
emit(event: string | symbol, ...args: any[]): boolean;
|
|
523
|
-
on(event: "error", listener: (err: Error) => void): this;
|
|
524
|
-
on(event: "exit", listener: (exitCode: number) => void): this;
|
|
525
|
-
on(event: "message", listener: (value: any) => void): this;
|
|
526
|
-
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
527
|
-
on(event: "online", listener: () => void): this;
|
|
528
|
-
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
529
|
-
once(event: "error", listener: (err: Error) => void): this;
|
|
530
|
-
once(event: "exit", listener: (exitCode: number) => void): this;
|
|
531
|
-
once(event: "message", listener: (value: any) => void): this;
|
|
532
|
-
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
533
|
-
once(event: "online", listener: () => void): this;
|
|
534
|
-
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
535
|
-
prependListener(event: "error", listener: (err: Error) => void): this;
|
|
536
|
-
prependListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
537
|
-
prependListener(event: "message", listener: (value: any) => void): this;
|
|
538
|
-
prependListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
539
|
-
prependListener(event: "online", listener: () => void): this;
|
|
540
|
-
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
541
|
-
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
|
542
|
-
prependOnceListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
543
|
-
prependOnceListener(event: "message", listener: (value: any) => void): this;
|
|
544
|
-
prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
545
|
-
prependOnceListener(event: "online", listener: () => void): this;
|
|
546
|
-
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
547
|
-
removeListener(event: "error", listener: (err: Error) => void): this;
|
|
548
|
-
removeListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
549
|
-
removeListener(event: "message", listener: (value: any) => void): this;
|
|
550
|
-
removeListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
551
|
-
removeListener(event: "online", listener: () => void): this;
|
|
552
|
-
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
553
|
-
off(event: "error", listener: (err: Error) => void): this;
|
|
554
|
-
off(event: "exit", listener: (exitCode: number) => void): this;
|
|
555
|
-
off(event: "message", listener: (value: any) => void): this;
|
|
556
|
-
off(event: "messageerror", listener: (error: Error) => void): this;
|
|
557
|
-
off(event: "online", listener: () => void): this;
|
|
558
|
-
off(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
559
|
-
}
|
|
560
|
-
interface BroadcastChannel extends NodeJS.RefCounted {}
|
|
561
|
-
/**
|
|
562
|
-
* Instances of `BroadcastChannel` allow asynchronous one-to-many communication
|
|
563
|
-
* with all other `BroadcastChannel` instances bound to the same channel name.
|
|
564
|
-
*
|
|
565
|
-
* ```js
|
|
566
|
-
* 'use strict';
|
|
567
|
-
*
|
|
568
|
-
* import {
|
|
569
|
-
* isMainThread,
|
|
570
|
-
* BroadcastChannel,
|
|
571
|
-
* Worker,
|
|
572
|
-
* } from 'node:worker_threads';
|
|
573
|
-
*
|
|
574
|
-
* const bc = new BroadcastChannel('hello');
|
|
575
|
-
*
|
|
576
|
-
* if (isMainThread) {
|
|
577
|
-
* let c = 0;
|
|
578
|
-
* bc.onmessage = (event) => {
|
|
579
|
-
* console.log(event.data);
|
|
580
|
-
* if (++c === 10) bc.close();
|
|
581
|
-
* };
|
|
582
|
-
* for (let n = 0; n < 10; n++)
|
|
583
|
-
* new Worker(__filename);
|
|
584
|
-
* } else {
|
|
585
|
-
* bc.postMessage('hello from every worker');
|
|
586
|
-
* bc.close();
|
|
587
|
-
* }
|
|
588
|
-
* ```
|
|
589
|
-
* @since v15.4.0
|
|
590
|
-
*/
|
|
591
|
-
class BroadcastChannel extends EventTarget {
|
|
592
|
-
readonly name: string;
|
|
593
|
-
/**
|
|
594
|
-
* Invoked with a single \`MessageEvent\` argument when a message is received.
|
|
595
|
-
* @since v15.4.0
|
|
596
|
-
*/
|
|
597
|
-
onmessage: (message: MessageEvent) => void;
|
|
598
|
-
/**
|
|
599
|
-
* Invoked with a received message cannot be deserialized.
|
|
600
|
-
* @since v15.4.0
|
|
601
|
-
*/
|
|
602
|
-
onmessageerror: (message: MessageEvent) => void;
|
|
603
|
-
constructor(name: string);
|
|
604
|
-
/**
|
|
605
|
-
* Closes the `BroadcastChannel` connection.
|
|
606
|
-
* @since v15.4.0
|
|
607
|
-
*/
|
|
608
|
-
close(): void;
|
|
609
|
-
/**
|
|
610
|
-
* @since v15.4.0
|
|
611
|
-
* @param message Any cloneable JavaScript value.
|
|
612
|
-
*/
|
|
613
|
-
postMessage(message: unknown): void;
|
|
614
338
|
}
|
|
339
|
+
interface Worker extends InternalEventEmitter<WorkerEventMap> {}
|
|
615
340
|
/**
|
|
616
341
|
* Mark an object as not transferable. If `object` occurs in the transfer list of
|
|
617
|
-
* a `port.postMessage()` call,
|
|
342
|
+
* a [`port.postMessage()`](https://nodejs.org/docs/latest-v26.x/api/worker_threads.html#portpostmessagevalue-transferlist) call, an error is thrown. This is a no-op if
|
|
343
|
+
* `object` is a primitive value.
|
|
618
344
|
*
|
|
619
345
|
* In particular, this makes sense for objects that can be cloned, rather than
|
|
620
346
|
* transferred, and which are used by other objects on the sending side.
|
|
621
|
-
* For example, Node.js marks the `ArrayBuffer`s it uses for its
|
|
347
|
+
* For example, Node.js marks the `ArrayBuffer`s it uses for its
|
|
348
|
+
* [`Buffer` pool](https://nodejs.org/docs/latest-v26.x/api/buffer.html#static-method-bufferallocunsafesize) with this.
|
|
349
|
+
* `ArrayBuffer.prototype.transfer()` is disallowed on such array buffer
|
|
350
|
+
* instances.
|
|
622
351
|
*
|
|
623
352
|
* This operation cannot be undone.
|
|
624
353
|
*
|
|
@@ -632,11 +361,17 @@ declare module "worker_threads" {
|
|
|
632
361
|
* markAsUntransferable(pooledBuffer);
|
|
633
362
|
*
|
|
634
363
|
* const { port1 } = new MessageChannel();
|
|
635
|
-
*
|
|
364
|
+
* try {
|
|
365
|
+
* // This will throw an error, because pooledBuffer is not transferable.
|
|
366
|
+
* port1.postMessage(typedArray1, [ typedArray1.buffer ]);
|
|
367
|
+
* } catch (error) {
|
|
368
|
+
* // error.name === 'DataCloneError'
|
|
369
|
+
* }
|
|
636
370
|
*
|
|
637
371
|
* // The following line prints the contents of typedArray1 -- it still owns
|
|
638
|
-
* // its memory and has been
|
|
639
|
-
* // `markAsUntransferable()`, this would print an empty Uint8Array
|
|
372
|
+
* // its memory and has not been transferred. Without
|
|
373
|
+
* // `markAsUntransferable()`, this would print an empty Uint8Array and the
|
|
374
|
+
* // postMessage call would have succeeded.
|
|
640
375
|
* // typedArray2 is intact as well.
|
|
641
376
|
* console.log(typedArray1);
|
|
642
377
|
* console.log(typedArray2);
|
|
@@ -771,49 +506,167 @@ declare module "worker_threads" {
|
|
|
771
506
|
transferList: readonly Transferable[],
|
|
772
507
|
timeout?: number,
|
|
773
508
|
): Promise<void>;
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
MessagePort
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
509
|
+
// #region web types
|
|
510
|
+
type LockMode = "exclusive" | "shared";
|
|
511
|
+
type Transferable =
|
|
512
|
+
| ArrayBuffer
|
|
513
|
+
| MessagePort
|
|
514
|
+
| AbortSignal
|
|
515
|
+
| FileHandle
|
|
516
|
+
| ReadableStream
|
|
517
|
+
| WritableStream
|
|
518
|
+
| TransformStream
|
|
519
|
+
| Server
|
|
520
|
+
| Socket;
|
|
521
|
+
interface LockGrantedCallback<T> {
|
|
522
|
+
(lock: Lock | null): T;
|
|
523
|
+
}
|
|
524
|
+
interface LockInfo {
|
|
525
|
+
clientId: string;
|
|
526
|
+
mode: LockMode;
|
|
527
|
+
name: string;
|
|
528
|
+
}
|
|
529
|
+
interface LockManagerSnapshot {
|
|
530
|
+
held: LockInfo[];
|
|
531
|
+
pending: LockInfo[];
|
|
532
|
+
}
|
|
533
|
+
interface LockOptions {
|
|
534
|
+
ifAvailable?: boolean;
|
|
535
|
+
mode?: LockMode;
|
|
536
|
+
signal?: AbortSignal;
|
|
537
|
+
steal?: boolean;
|
|
538
|
+
}
|
|
539
|
+
interface StructuredSerializeOptions {
|
|
540
|
+
transfer?: Transferable[];
|
|
541
|
+
}
|
|
542
|
+
interface BroadcastChannelEventMap {
|
|
543
|
+
"message": MessageEvent;
|
|
544
|
+
"messageerror": MessageEvent;
|
|
545
|
+
}
|
|
546
|
+
interface BroadcastChannel
|
|
547
|
+
extends EventTarget, InternalEventTargetEventProperties<BroadcastChannelEventMap>, NodeJS.RefCounted
|
|
548
|
+
{
|
|
549
|
+
readonly name: string;
|
|
550
|
+
close(): void;
|
|
551
|
+
postMessage(message: any): void;
|
|
552
|
+
addEventListener<K extends keyof BroadcastChannelEventMap>(
|
|
553
|
+
type: K,
|
|
554
|
+
listener: (ev: BroadcastChannelEventMap[K]) => void,
|
|
555
|
+
options?: AddEventListenerOptions | boolean,
|
|
556
|
+
): void;
|
|
557
|
+
addEventListener(
|
|
558
|
+
type: string,
|
|
559
|
+
listener: EventListener | EventListenerObject,
|
|
560
|
+
options?: AddEventListenerOptions | boolean,
|
|
561
|
+
): void;
|
|
562
|
+
removeEventListener<K extends keyof BroadcastChannelEventMap>(
|
|
563
|
+
type: K,
|
|
564
|
+
listener: (ev: BroadcastChannelEventMap[K]) => void,
|
|
565
|
+
options?: EventListenerOptions | boolean,
|
|
566
|
+
): void;
|
|
567
|
+
removeEventListener(
|
|
568
|
+
type: string,
|
|
569
|
+
listener: EventListener | EventListenerObject,
|
|
570
|
+
options?: EventListenerOptions | boolean,
|
|
571
|
+
): void;
|
|
572
|
+
}
|
|
573
|
+
var BroadcastChannel: {
|
|
574
|
+
prototype: BroadcastChannel;
|
|
575
|
+
new(name: string): BroadcastChannel;
|
|
576
|
+
};
|
|
577
|
+
interface Lock {
|
|
578
|
+
readonly mode: LockMode;
|
|
579
|
+
readonly name: string;
|
|
580
|
+
}
|
|
581
|
+
// var Lock: {
|
|
582
|
+
// prototype: Lock;
|
|
583
|
+
// new(): Lock;
|
|
584
|
+
// };
|
|
585
|
+
interface LockManager {
|
|
586
|
+
query(): Promise<LockManagerSnapshot>;
|
|
587
|
+
request<T>(name: string, callback: LockGrantedCallback<T>): Promise<Awaited<T>>;
|
|
588
|
+
request<T>(name: string, options: LockOptions, callback: LockGrantedCallback<T>): Promise<Awaited<T>>;
|
|
589
|
+
}
|
|
590
|
+
// var LockManager: {
|
|
591
|
+
// prototype: LockManager;
|
|
592
|
+
// new(): LockManager;
|
|
593
|
+
// };
|
|
594
|
+
interface MessageChannel {
|
|
595
|
+
readonly port1: MessagePort;
|
|
596
|
+
readonly port2: MessagePort;
|
|
597
|
+
}
|
|
598
|
+
var MessageChannel: {
|
|
599
|
+
prototype: MessageChannel;
|
|
600
|
+
new(): MessageChannel;
|
|
601
|
+
};
|
|
602
|
+
interface MessagePortEventMap {
|
|
603
|
+
"close": Event;
|
|
604
|
+
"message": MessageEvent;
|
|
605
|
+
"messageerror": MessageEvent;
|
|
606
|
+
}
|
|
607
|
+
interface MessagePort extends NodeEventTarget, InternalEventTargetEventProperties<MessagePortEventMap> {
|
|
608
|
+
close(): void;
|
|
609
|
+
postMessage(message: any, transfer: Transferable[]): void;
|
|
610
|
+
postMessage(message: any, options?: StructuredSerializeOptions): void;
|
|
611
|
+
start(): void;
|
|
612
|
+
hasRef(): boolean;
|
|
613
|
+
ref(): void;
|
|
614
|
+
unref(): void;
|
|
615
|
+
addEventListener<K extends keyof MessagePortEventMap>(
|
|
616
|
+
type: K,
|
|
617
|
+
listener: (ev: MessagePortEventMap[K]) => void,
|
|
618
|
+
options?: AddEventListenerOptions | boolean,
|
|
619
|
+
): void;
|
|
620
|
+
addEventListener(
|
|
621
|
+
type: string,
|
|
622
|
+
listener: EventListener | EventListenerObject,
|
|
623
|
+
options?: AddEventListenerOptions | boolean,
|
|
624
|
+
): void;
|
|
625
|
+
removeEventListener<K extends keyof MessagePortEventMap>(
|
|
626
|
+
type: K,
|
|
627
|
+
listener: (ev: MessagePortEventMap[K]) => void,
|
|
628
|
+
options?: EventListenerOptions | boolean,
|
|
629
|
+
): void;
|
|
630
|
+
removeEventListener(
|
|
631
|
+
type: string,
|
|
632
|
+
listener: EventListener | EventListenerObject,
|
|
633
|
+
options?: EventListenerOptions | boolean,
|
|
634
|
+
): void;
|
|
635
|
+
// #region NodeEventTarget
|
|
636
|
+
addListener(event: "close", listener: (ev: Event) => void): this;
|
|
637
|
+
addListener(event: "message", listener: (value: any) => void): this;
|
|
638
|
+
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
639
|
+
addListener(event: string, listener: (arg: any) => void): this;
|
|
640
|
+
emit(event: "close", ev: Event): boolean;
|
|
641
|
+
emit(event: "message", value: any): boolean;
|
|
642
|
+
emit(event: "messageerror", error: Error): boolean;
|
|
643
|
+
emit(event: string, arg: any): boolean;
|
|
644
|
+
off(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
645
|
+
off(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
646
|
+
off(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
647
|
+
off(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
648
|
+
on(event: "close", listener: (ev: Event) => void): this;
|
|
649
|
+
on(event: "message", listener: (value: any) => void): this;
|
|
650
|
+
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
651
|
+
on(event: string, listener: (arg: any) => void): this;
|
|
652
|
+
once(event: "close", listener: (ev: Event) => void): this;
|
|
653
|
+
once(event: "message", listener: (value: any) => void): this;
|
|
654
|
+
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
655
|
+
once(event: string, listener: (arg: any) => void): this;
|
|
656
|
+
removeListener(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
657
|
+
removeListener(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
658
|
+
removeListener(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
659
|
+
removeListener(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
660
|
+
// #endregion
|
|
815
661
|
}
|
|
662
|
+
var MessagePort: {
|
|
663
|
+
prototype: MessagePort;
|
|
664
|
+
new(): MessagePort;
|
|
665
|
+
};
|
|
666
|
+
var locks: LockManager;
|
|
667
|
+
export import structuredClone = globalThis.structuredClone;
|
|
668
|
+
// #endregion
|
|
816
669
|
}
|
|
817
|
-
declare module "
|
|
818
|
-
export * from "worker_threads";
|
|
670
|
+
declare module "worker_threads" {
|
|
671
|
+
export * from "node:worker_threads";
|
|
819
672
|
}
|