@emnapi/wasi-threads 1.2.2 → 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 -63
- package/dist/wasi-threads.js +789 -846
- package/package.json +7 -22
- package/rollup.config.js +6 -0
- package/dist/wasi-threads.cjs.js +0 -885
- package/dist/wasi-threads.cjs.min.d.ts +0 -271
- package/dist/wasi-threads.cjs.min.js +0 -1
- package/dist/wasi-threads.d.mts +0 -271
- package/dist/wasi-threads.esm-bundler.js +0 -933
- package/dist/wasi-threads.min.d.mts +0 -271
- package/dist/wasi-threads.min.js +0 -1
- package/dist/wasi-threads.min.mjs +0 -1
- package/dist/wasi-threads.mjs +0 -880
- 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,87 +29,64 @@ 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
92
|
pthreads: Record<number, WorkerLike>;
|
|
@@ -128,7 +98,7 @@ export declare class ThreadManager {
|
|
|
128
98
|
private readonly _onCreateWorker;
|
|
129
99
|
private readonly _reuseWorker;
|
|
130
100
|
private readonly _beforeLoad?;
|
|
131
|
-
|
|
101
|
+
readonly printErr: (message: string) => void;
|
|
132
102
|
threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
|
|
133
103
|
constructor(options: ThreadManagerOptions);
|
|
134
104
|
init(): void;
|
|
@@ -150,21 +120,17 @@ export declare class ThreadManager {
|
|
|
150
120
|
fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
|
|
151
121
|
}
|
|
152
122
|
|
|
153
|
-
/** @public */
|
|
154
123
|
export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
|
|
155
124
|
|
|
156
|
-
/** @public */
|
|
157
125
|
export declare interface ThreadManagerOptionsBase {
|
|
158
126
|
printErr?: (message: string) => void;
|
|
159
127
|
threadSpawn?: (startArg: number, errorOrTid?: number) => number;
|
|
160
128
|
}
|
|
161
129
|
|
|
162
|
-
/** @public */
|
|
163
130
|
export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
|
|
164
131
|
childThread: true;
|
|
165
132
|
}
|
|
166
133
|
|
|
167
|
-
/** @public */
|
|
168
134
|
export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
|
|
169
135
|
beforeLoad?: (worker: WorkerLike) => any;
|
|
170
136
|
reuseWorker?: boolean | number | ReuseWorkerOptions;
|
|
@@ -172,7 +138,6 @@ export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBa
|
|
|
172
138
|
childThread?: false;
|
|
173
139
|
}
|
|
174
140
|
|
|
175
|
-
/** @public */
|
|
176
141
|
export declare class ThreadMessageHandler {
|
|
177
142
|
protected instance: WebAssembly.Instance | undefined;
|
|
178
143
|
private messagesBeforeLoad;
|
|
@@ -180,9 +145,7 @@ export declare class ThreadMessageHandler {
|
|
|
180
145
|
protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
|
|
181
146
|
protected onError: (error: Error, type: WorkerMessageType) => void;
|
|
182
147
|
constructor(options?: ThreadMessageHandlerOptions);
|
|
183
|
-
/** @virtual */
|
|
184
148
|
instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
|
|
185
|
-
/** @virtual */
|
|
186
149
|
handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
|
|
187
150
|
private _load;
|
|
188
151
|
private _start;
|
|
@@ -190,14 +153,12 @@ export declare class ThreadMessageHandler {
|
|
|
190
153
|
protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
|
|
191
154
|
}
|
|
192
155
|
|
|
193
|
-
/** @public */
|
|
194
156
|
export declare interface ThreadMessageHandlerOptions {
|
|
195
157
|
onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
|
|
196
158
|
onError?: (error: Error, type: WorkerMessageType) => void;
|
|
197
159
|
postMessage?: (message: any) => void;
|
|
198
160
|
}
|
|
199
161
|
|
|
200
|
-
/** @public */
|
|
201
162
|
export declare interface WASIInstance {
|
|
202
163
|
readonly wasiImport?: Record<string, any>;
|
|
203
164
|
initialize(instance: object): void;
|
|
@@ -205,7 +166,6 @@ export declare interface WASIInstance {
|
|
|
205
166
|
getImportObject?(): any;
|
|
206
167
|
}
|
|
207
168
|
|
|
208
|
-
/** @public */
|
|
209
169
|
export declare class WASIThreads {
|
|
210
170
|
PThread: ThreadManager | undefined;
|
|
211
171
|
private wasmMemory;
|
|
@@ -220,54 +180,32 @@ export declare class WASIThreads {
|
|
|
220
180
|
};
|
|
221
181
|
setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
|
|
222
182
|
preloadWorkers(): Promise<WorkerLike[]>;
|
|
223
|
-
/**
|
|
224
|
-
* It's ok to call this method to a WASI command module.
|
|
225
|
-
*
|
|
226
|
-
* in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
|
|
227
|
-
*
|
|
228
|
-
* @returns A proxied WebAssembly instance if in child thread, other wise the original instance
|
|
229
|
-
*/
|
|
230
183
|
initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
|
|
231
|
-
/**
|
|
232
|
-
* Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
|
|
233
|
-
* ```js
|
|
234
|
-
* this.initialize(instance, module, memory)
|
|
235
|
-
* this.wasi.start(instance)
|
|
236
|
-
* ```
|
|
237
|
-
*/
|
|
238
184
|
start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
|
|
239
185
|
terminateAllThreads(): void;
|
|
240
186
|
}
|
|
241
187
|
|
|
242
|
-
/** @public */
|
|
243
188
|
export declare interface WASIThreadsImports {
|
|
244
189
|
'thread-spawn': (startArg: number, errorOrTid?: number) => number;
|
|
245
190
|
}
|
|
246
191
|
|
|
247
|
-
/** @public */
|
|
248
192
|
export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
|
|
249
193
|
|
|
250
|
-
/** @public */
|
|
251
194
|
export declare type WorkerFactory = (ctx: {
|
|
252
195
|
type: string;
|
|
253
196
|
name: string;
|
|
254
197
|
}) => WorkerLike;
|
|
255
198
|
|
|
256
|
-
/** @public */
|
|
257
199
|
export declare type WorkerLike = (Worker | Worker_2) & {
|
|
258
200
|
whenLoaded?: Promise<WorkerLike>;
|
|
259
201
|
loaded?: boolean;
|
|
260
202
|
__emnapi_tid?: number;
|
|
261
203
|
};
|
|
262
204
|
|
|
263
|
-
/** @public */
|
|
264
205
|
export declare interface WorkerMessageEvent<T = any> {
|
|
265
206
|
data: T;
|
|
266
207
|
}
|
|
267
208
|
|
|
268
|
-
/** @public */
|
|
269
209
|
export declare type WorkerMessageType = 'load' | 'start';
|
|
270
210
|
|
|
271
211
|
export { }
|
|
272
|
-
|
|
273
|
-
export as namespace wasiThreads;
|