@emnapi/wasi-threads 1.2.1 → 2.0.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/dist/wasi-threads.d.ts +1 -64
- package/dist/wasi-threads.js +789 -855
- package/package.json +7 -22
- package/rollup.config.js +6 -0
- package/dist/wasi-threads.cjs.js +0 -894
- package/dist/wasi-threads.cjs.min.d.ts +0 -272
- package/dist/wasi-threads.cjs.min.js +0 -1
- package/dist/wasi-threads.d.mts +0 -272
- package/dist/wasi-threads.esm-bundler.js +0 -942
- package/dist/wasi-threads.min.d.mts +0 -272
- package/dist/wasi-threads.min.js +0 -1
- package/dist/wasi-threads.min.mjs +0 -1
- package/dist/wasi-threads.mjs +0 -889
- package/index.js +0 -5
package/dist/wasi-threads.d.ts
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
1
|
import type { Worker as Worker_2 } from 'worker_threads';
|
|
4
2
|
|
|
5
|
-
/** @public */
|
|
6
3
|
export declare interface BaseOptions {
|
|
7
4
|
wasi: WASIInstance;
|
|
8
5
|
version?: 'preview1';
|
|
9
6
|
wasm64?: boolean;
|
|
10
7
|
}
|
|
11
8
|
|
|
12
|
-
/** @public */
|
|
13
9
|
export declare interface ChildThreadOptions extends BaseOptions {
|
|
14
10
|
childThread: true;
|
|
15
11
|
postMessage?: (data: any) => void;
|
|
16
12
|
}
|
|
17
13
|
|
|
18
|
-
/** @public */
|
|
19
14
|
export declare interface CleanupThreadPayload {
|
|
20
15
|
tid: number;
|
|
21
16
|
}
|
|
22
17
|
|
|
23
|
-
/** @public */
|
|
24
18
|
export declare interface CommandInfo<T extends CommandType> {
|
|
25
19
|
type: T;
|
|
26
20
|
payload: CommandPayloadMap[T];
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
/** @public */
|
|
30
23
|
export declare interface CommandPayloadMap {
|
|
31
24
|
load: LoadPayload;
|
|
32
25
|
loaded: LoadedPayload;
|
|
@@ -36,90 +29,66 @@ export declare interface CommandPayloadMap {
|
|
|
36
29
|
'spawn-thread': SpawnThreadPayload;
|
|
37
30
|
}
|
|
38
31
|
|
|
39
|
-
/** @public */
|
|
40
32
|
export declare type CommandType = keyof CommandPayloadMap;
|
|
41
33
|
|
|
42
|
-
/** @public */
|
|
43
34
|
export declare function createInstanceProxy(instance: WebAssembly.Instance, memory?: WebAssembly.Memory | (() => WebAssembly.Memory)): WebAssembly.Instance;
|
|
44
35
|
|
|
45
|
-
/** @public */
|
|
46
36
|
export declare function isSharedArrayBuffer(value: any): value is SharedArrayBuffer;
|
|
47
37
|
|
|
48
|
-
/** @public */
|
|
49
38
|
export declare function isTrapError(e: Error): e is WebAssembly.RuntimeError;
|
|
50
39
|
|
|
51
|
-
/** @public */
|
|
52
40
|
export declare interface LoadedPayload {
|
|
53
41
|
}
|
|
54
42
|
|
|
55
|
-
/** @public */
|
|
56
43
|
export declare interface LoadPayload {
|
|
57
44
|
wasmModule: WebAssembly.Module;
|
|
58
45
|
wasmMemory: WebAssembly.Memory;
|
|
59
46
|
sab?: Int32Array;
|
|
60
47
|
}
|
|
61
48
|
|
|
62
|
-
/** @public */
|
|
63
49
|
export declare interface MainThreadBaseOptions extends BaseOptions {
|
|
64
50
|
waitThreadStart?: boolean | number;
|
|
65
51
|
}
|
|
66
52
|
|
|
67
|
-
/** @public */
|
|
68
53
|
export declare type MainThreadOptions = MainThreadOptionsWithThreadManager | MainThreadOptionsCreateThreadManager;
|
|
69
54
|
|
|
70
|
-
/** @public */
|
|
71
55
|
export declare interface MainThreadOptionsCreateThreadManager extends MainThreadBaseOptions, ThreadManagerOptionsMain {
|
|
72
56
|
}
|
|
73
57
|
|
|
74
|
-
/** @public */
|
|
75
58
|
export declare interface MainThreadOptionsWithThreadManager extends MainThreadBaseOptions {
|
|
76
59
|
threadManager?: ThreadManager | (() => ThreadManager);
|
|
77
60
|
}
|
|
78
61
|
|
|
79
|
-
/** @public */
|
|
80
62
|
export declare interface MessageEventData<T extends CommandType> {
|
|
81
63
|
__emnapi__: CommandInfo<T>;
|
|
82
64
|
}
|
|
83
65
|
|
|
84
|
-
/** @public */
|
|
85
66
|
export declare interface ReuseWorkerOptions {
|
|
86
|
-
/**
|
|
87
|
-
* @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
|
|
88
|
-
*/
|
|
89
67
|
size: number;
|
|
90
|
-
/**
|
|
91
|
-
* @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
|
|
92
|
-
*/
|
|
93
68
|
strict?: boolean;
|
|
94
69
|
}
|
|
95
70
|
|
|
96
|
-
/** @public */
|
|
97
71
|
export declare interface SpawnThreadPayload {
|
|
98
72
|
startArg: number;
|
|
99
73
|
errorOrTid: number;
|
|
100
74
|
}
|
|
101
75
|
|
|
102
|
-
/** @public */
|
|
103
76
|
export declare interface StartPayload {
|
|
104
77
|
tid: number;
|
|
105
78
|
arg: number;
|
|
106
79
|
sab?: Int32Array;
|
|
107
80
|
}
|
|
108
81
|
|
|
109
|
-
/** @public */
|
|
110
82
|
export declare interface StartResult {
|
|
111
83
|
exitCode: number;
|
|
112
84
|
instance: WebAssembly.Instance;
|
|
113
85
|
}
|
|
114
86
|
|
|
115
|
-
/** @public */
|
|
116
87
|
export declare interface TerminateAllThreadsPayload {
|
|
117
88
|
}
|
|
118
89
|
|
|
119
|
-
/** @public */
|
|
120
90
|
export declare class ThreadManager {
|
|
121
91
|
unusedWorkers: WorkerLike[];
|
|
122
|
-
runningWorkers: WorkerLike[];
|
|
123
92
|
pthreads: Record<number, WorkerLike>;
|
|
124
93
|
get nextWorkerID(): number;
|
|
125
94
|
wasmModule: WebAssembly.Module | null;
|
|
@@ -129,7 +98,7 @@ export declare class ThreadManager {
|
|
|
129
98
|
private readonly _onCreateWorker;
|
|
130
99
|
private readonly _reuseWorker;
|
|
131
100
|
private readonly _beforeLoad?;
|
|
132
|
-
|
|
101
|
+
readonly printErr: (message: string) => void;
|
|
133
102
|
threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
|
|
134
103
|
constructor(options: ThreadManagerOptions);
|
|
135
104
|
init(): void;
|
|
@@ -151,21 +120,17 @@ export declare class ThreadManager {
|
|
|
151
120
|
fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
|
|
152
121
|
}
|
|
153
122
|
|
|
154
|
-
/** @public */
|
|
155
123
|
export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
|
|
156
124
|
|
|
157
|
-
/** @public */
|
|
158
125
|
export declare interface ThreadManagerOptionsBase {
|
|
159
126
|
printErr?: (message: string) => void;
|
|
160
127
|
threadSpawn?: (startArg: number, errorOrTid?: number) => number;
|
|
161
128
|
}
|
|
162
129
|
|
|
163
|
-
/** @public */
|
|
164
130
|
export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
|
|
165
131
|
childThread: true;
|
|
166
132
|
}
|
|
167
133
|
|
|
168
|
-
/** @public */
|
|
169
134
|
export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
|
|
170
135
|
beforeLoad?: (worker: WorkerLike) => any;
|
|
171
136
|
reuseWorker?: boolean | number | ReuseWorkerOptions;
|
|
@@ -173,7 +138,6 @@ export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBa
|
|
|
173
138
|
childThread?: false;
|
|
174
139
|
}
|
|
175
140
|
|
|
176
|
-
/** @public */
|
|
177
141
|
export declare class ThreadMessageHandler {
|
|
178
142
|
protected instance: WebAssembly.Instance | undefined;
|
|
179
143
|
private messagesBeforeLoad;
|
|
@@ -181,9 +145,7 @@ export declare class ThreadMessageHandler {
|
|
|
181
145
|
protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
|
|
182
146
|
protected onError: (error: Error, type: WorkerMessageType) => void;
|
|
183
147
|
constructor(options?: ThreadMessageHandlerOptions);
|
|
184
|
-
/** @virtual */
|
|
185
148
|
instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
|
|
186
|
-
/** @virtual */
|
|
187
149
|
handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
|
|
188
150
|
private _load;
|
|
189
151
|
private _start;
|
|
@@ -191,14 +153,12 @@ export declare class ThreadMessageHandler {
|
|
|
191
153
|
protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
|
|
192
154
|
}
|
|
193
155
|
|
|
194
|
-
/** @public */
|
|
195
156
|
export declare interface ThreadMessageHandlerOptions {
|
|
196
157
|
onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
|
|
197
158
|
onError?: (error: Error, type: WorkerMessageType) => void;
|
|
198
159
|
postMessage?: (message: any) => void;
|
|
199
160
|
}
|
|
200
161
|
|
|
201
|
-
/** @public */
|
|
202
162
|
export declare interface WASIInstance {
|
|
203
163
|
readonly wasiImport?: Record<string, any>;
|
|
204
164
|
initialize(instance: object): void;
|
|
@@ -206,7 +166,6 @@ export declare interface WASIInstance {
|
|
|
206
166
|
getImportObject?(): any;
|
|
207
167
|
}
|
|
208
168
|
|
|
209
|
-
/** @public */
|
|
210
169
|
export declare class WASIThreads {
|
|
211
170
|
PThread: ThreadManager | undefined;
|
|
212
171
|
private wasmMemory;
|
|
@@ -221,54 +180,32 @@ export declare class WASIThreads {
|
|
|
221
180
|
};
|
|
222
181
|
setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
|
|
223
182
|
preloadWorkers(): Promise<WorkerLike[]>;
|
|
224
|
-
/**
|
|
225
|
-
* It's ok to call this method to a WASI command module.
|
|
226
|
-
*
|
|
227
|
-
* in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
|
|
228
|
-
*
|
|
229
|
-
* @returns A proxied WebAssembly instance if in child thread, other wise the original instance
|
|
230
|
-
*/
|
|
231
183
|
initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
|
|
232
|
-
/**
|
|
233
|
-
* Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
|
|
234
|
-
* ```js
|
|
235
|
-
* this.initialize(instance, module, memory)
|
|
236
|
-
* this.wasi.start(instance)
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
184
|
start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
|
|
240
185
|
terminateAllThreads(): void;
|
|
241
186
|
}
|
|
242
187
|
|
|
243
|
-
/** @public */
|
|
244
188
|
export declare interface WASIThreadsImports {
|
|
245
189
|
'thread-spawn': (startArg: number, errorOrTid?: number) => number;
|
|
246
190
|
}
|
|
247
191
|
|
|
248
|
-
/** @public */
|
|
249
192
|
export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
|
|
250
193
|
|
|
251
|
-
/** @public */
|
|
252
194
|
export declare type WorkerFactory = (ctx: {
|
|
253
195
|
type: string;
|
|
254
196
|
name: string;
|
|
255
197
|
}) => WorkerLike;
|
|
256
198
|
|
|
257
|
-
/** @public */
|
|
258
199
|
export declare type WorkerLike = (Worker | Worker_2) & {
|
|
259
200
|
whenLoaded?: Promise<WorkerLike>;
|
|
260
201
|
loaded?: boolean;
|
|
261
202
|
__emnapi_tid?: number;
|
|
262
203
|
};
|
|
263
204
|
|
|
264
|
-
/** @public */
|
|
265
205
|
export declare interface WorkerMessageEvent<T = any> {
|
|
266
206
|
data: T;
|
|
267
207
|
}
|
|
268
208
|
|
|
269
|
-
/** @public */
|
|
270
209
|
export declare type WorkerMessageType = 'load' | 'start';
|
|
271
210
|
|
|
272
211
|
export { }
|
|
273
|
-
|
|
274
|
-
export as namespace wasiThreads;
|