@xylabs/threads 5.0.14 → 5.0.15
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/browser/index-browser.mjs +119 -209
- package/dist/browser/index-browser.mjs.map +1 -1
- package/dist/browser/master/implementation.browser.mjs +11 -36
- package/dist/browser/master/implementation.browser.mjs.map +1 -1
- package/dist/browser/master/index-browser.mjs +117 -201
- package/dist/browser/master/index-browser.mjs.map +1 -1
- package/dist/browser/master/pool-browser.mjs +53 -65
- package/dist/browser/master/pool-browser.mjs.map +1 -1
- package/dist/browser/worker/worker.browser.mjs +43 -79
- package/dist/browser/worker/worker.browser.mjs.map +1 -1
- package/dist/neutral/master/register.mjs +62 -121
- package/dist/neutral/master/register.mjs.map +1 -1
- package/dist/neutral/master/spawn.mjs +53 -106
- package/dist/neutral/master/spawn.mjs.map +1 -1
- package/dist/neutral/master/thread.mjs +0 -4
- package/dist/neutral/master/thread.mjs.map +1 -1
- package/dist/neutral/observable-promise.mjs +20 -27
- package/dist/neutral/observable-promise.mjs.map +1 -1
- package/dist/neutral/observable.mjs +3 -12
- package/dist/neutral/observable.mjs.map +1 -1
- package/dist/neutral/types/messages.mjs +4 -4
- package/dist/neutral/types/messages.mjs.map +1 -1
- package/dist/node/index-node.mjs +169 -293
- package/dist/node/index-node.mjs.map +1 -1
- package/dist/node/master/implementation.node.mjs +62 -121
- package/dist/node/master/implementation.node.mjs.map +1 -1
- package/dist/node/master/index-node.mjs +168 -286
- package/dist/node/master/index-node.mjs.map +1 -1
- package/dist/node/master/pool-node.mjs +115 -183
- package/dist/node/master/pool-node.mjs.map +1 -1
- package/dist/node/worker/worker.node.mjs +43 -80
- package/dist/node/worker/worker.node.mjs.map +1 -1
- package/package.json +3 -4
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/worker/expose.ts
|
|
5
2
|
import isSomeObservable from "is-observable-2-1-0";
|
|
6
3
|
|
|
@@ -17,7 +14,6 @@ function extendSerializer(extend, implementation) {
|
|
|
17
14
|
}
|
|
18
15
|
};
|
|
19
16
|
}
|
|
20
|
-
__name(extendSerializer, "extendSerializer");
|
|
21
17
|
var DefaultErrorSerializer = {
|
|
22
18
|
deserialize(message) {
|
|
23
19
|
return Object.assign(new Error(message.message), {
|
|
@@ -34,7 +30,7 @@ var DefaultErrorSerializer = {
|
|
|
34
30
|
};
|
|
35
31
|
}
|
|
36
32
|
};
|
|
37
|
-
var isSerializedError =
|
|
33
|
+
var isSerializedError = (thing) => thing && typeof thing === "object" && "__error_marker" in thing && thing.__error_marker === "$$error";
|
|
38
34
|
var DefaultSerializer = {
|
|
39
35
|
deserialize(message) {
|
|
40
36
|
return isSerializedError(message) ? DefaultErrorSerializer.deserialize(message) : message;
|
|
@@ -49,15 +45,12 @@ globalThis.registeredSerializer = globalThis.registeredSerializer ?? DefaultSeri
|
|
|
49
45
|
function registerSerializer(serializer) {
|
|
50
46
|
globalThis.registeredSerializer = extendSerializer(globalThis.registeredSerializer, serializer);
|
|
51
47
|
}
|
|
52
|
-
__name(registerSerializer, "registerSerializer");
|
|
53
48
|
function deserialize(message) {
|
|
54
49
|
return globalThis.registeredSerializer.deserialize(message);
|
|
55
50
|
}
|
|
56
|
-
__name(deserialize, "deserialize");
|
|
57
51
|
function serialize(input) {
|
|
58
52
|
return globalThis.registeredSerializer.serialize(input);
|
|
59
53
|
}
|
|
60
|
-
__name(serialize, "serialize");
|
|
61
54
|
|
|
62
55
|
// src/symbols.ts
|
|
63
56
|
var $errors = Symbol("thread.errors");
|
|
@@ -71,18 +64,14 @@ function isTransferable(thing) {
|
|
|
71
64
|
if (!thing || typeof thing !== "object") return false;
|
|
72
65
|
return true;
|
|
73
66
|
}
|
|
74
|
-
__name(isTransferable, "isTransferable");
|
|
75
67
|
function isTransferDescriptor(thing) {
|
|
76
68
|
return thing && typeof thing === "object" && thing[$transferable];
|
|
77
69
|
}
|
|
78
|
-
__name(isTransferDescriptor, "isTransferDescriptor");
|
|
79
70
|
function Transfer(payload, transferables) {
|
|
80
71
|
console.log("Transfer");
|
|
81
72
|
if (!transferables) {
|
|
82
73
|
if (!isTransferable(payload)) throw new Error("Not transferable");
|
|
83
|
-
transferables = [
|
|
84
|
-
payload
|
|
85
|
-
];
|
|
74
|
+
transferables = [payload];
|
|
86
75
|
}
|
|
87
76
|
return {
|
|
88
77
|
[$transferable]: true,
|
|
@@ -90,108 +79,81 @@ function Transfer(payload, transferables) {
|
|
|
90
79
|
transferables
|
|
91
80
|
};
|
|
92
81
|
}
|
|
93
|
-
__name(Transfer, "Transfer");
|
|
94
|
-
|
|
95
|
-
// src/types/messages.ts
|
|
96
|
-
var MasterMessageType = /* @__PURE__ */ function(MasterMessageType2) {
|
|
97
|
-
MasterMessageType2["cancel"] = "cancel";
|
|
98
|
-
MasterMessageType2["run"] = "run";
|
|
99
|
-
return MasterMessageType2;
|
|
100
|
-
}({});
|
|
101
|
-
var WorkerMessageType = /* @__PURE__ */ function(WorkerMessageType2) {
|
|
102
|
-
WorkerMessageType2["error"] = "error";
|
|
103
|
-
WorkerMessageType2["init"] = "init";
|
|
104
|
-
WorkerMessageType2["result"] = "result";
|
|
105
|
-
WorkerMessageType2["running"] = "running";
|
|
106
|
-
WorkerMessageType2["uncaughtError"] = "uncaughtError";
|
|
107
|
-
return WorkerMessageType2;
|
|
108
|
-
}({});
|
|
109
82
|
|
|
110
83
|
// src/worker/expose.ts
|
|
111
|
-
var isErrorEvent =
|
|
84
|
+
var isErrorEvent = (value) => value && value.error;
|
|
112
85
|
function createExpose(implementation, self2) {
|
|
113
86
|
let exposeCalled = false;
|
|
114
87
|
const activeSubscriptions = /* @__PURE__ */ new Map();
|
|
115
|
-
const isMasterJobCancelMessage =
|
|
116
|
-
const isMasterJobRunMessage =
|
|
117
|
-
const isObservable =
|
|
88
|
+
const isMasterJobCancelMessage = (thing) => thing && thing.type === "cancel" /* cancel */;
|
|
89
|
+
const isMasterJobRunMessage = (thing) => thing && thing.type === "run" /* run */;
|
|
90
|
+
const isObservable = (thing) => isSomeObservable(thing) || isZenObservable(thing);
|
|
118
91
|
function isZenObservable(thing) {
|
|
119
92
|
return thing && typeof thing === "object" && typeof thing.subscribe === "function";
|
|
120
93
|
}
|
|
121
|
-
__name(isZenObservable, "isZenObservable");
|
|
122
94
|
function deconstructTransfer(thing) {
|
|
123
|
-
return isTransferDescriptor(thing) ? {
|
|
124
|
-
payload: thing.send,
|
|
125
|
-
transferables: thing.transferables
|
|
126
|
-
} : {
|
|
127
|
-
payload: thing,
|
|
128
|
-
transferables: void 0
|
|
129
|
-
};
|
|
95
|
+
return isTransferDescriptor(thing) ? { payload: thing.send, transferables: thing.transferables } : { payload: thing, transferables: void 0 };
|
|
130
96
|
}
|
|
131
|
-
__name(deconstructTransfer, "deconstructTransfer");
|
|
132
97
|
function postFunctionInitMessage() {
|
|
133
98
|
const initMessage = {
|
|
134
|
-
exposed: {
|
|
135
|
-
|
|
136
|
-
},
|
|
137
|
-
type: WorkerMessageType.init
|
|
99
|
+
exposed: { type: "function" },
|
|
100
|
+
type: "init" /* init */
|
|
138
101
|
};
|
|
139
102
|
implementation.postMessageToMaster(initMessage);
|
|
140
103
|
}
|
|
141
|
-
__name(postFunctionInitMessage, "postFunctionInitMessage");
|
|
142
104
|
function postModuleInitMessage(methodNames) {
|
|
143
105
|
const initMessage = {
|
|
144
106
|
exposed: {
|
|
145
107
|
methods: methodNames,
|
|
146
108
|
type: "module"
|
|
147
109
|
},
|
|
148
|
-
type:
|
|
110
|
+
type: "init" /* init */
|
|
149
111
|
};
|
|
150
112
|
implementation.postMessageToMaster(initMessage);
|
|
151
113
|
}
|
|
152
|
-
__name(postModuleInitMessage, "postModuleInitMessage");
|
|
153
114
|
function postJobErrorMessage(uid, rawError) {
|
|
154
115
|
const { payload: error, transferables } = deconstructTransfer(rawError);
|
|
155
116
|
const errorMessage = {
|
|
156
117
|
error: serialize(error),
|
|
157
|
-
type:
|
|
118
|
+
type: "error" /* error */,
|
|
158
119
|
uid
|
|
159
120
|
};
|
|
160
121
|
implementation.postMessageToMaster(errorMessage, transferables);
|
|
161
122
|
}
|
|
162
|
-
__name(postJobErrorMessage, "postJobErrorMessage");
|
|
163
123
|
function postJobResultMessage(uid, completed, resultValue) {
|
|
164
124
|
const { payload, transferables } = deconstructTransfer(resultValue);
|
|
165
125
|
const resultMessage = {
|
|
166
126
|
complete: completed ? true : void 0,
|
|
167
127
|
payload,
|
|
168
|
-
type:
|
|
128
|
+
type: "result" /* result */,
|
|
169
129
|
uid
|
|
170
130
|
};
|
|
171
131
|
implementation.postMessageToMaster(resultMessage, transferables);
|
|
172
132
|
}
|
|
173
|
-
__name(postJobResultMessage, "postJobResultMessage");
|
|
174
133
|
function postJobStartMessage(uid, resultType) {
|
|
175
134
|
const startMessage = {
|
|
176
135
|
resultType,
|
|
177
|
-
type:
|
|
136
|
+
type: "running" /* running */,
|
|
178
137
|
uid
|
|
179
138
|
};
|
|
180
139
|
implementation.postMessageToMaster(startMessage);
|
|
181
140
|
}
|
|
182
|
-
__name(postJobStartMessage, "postJobStartMessage");
|
|
183
141
|
function postUncaughtErrorMessage(error) {
|
|
184
142
|
try {
|
|
185
143
|
const errorMessage = {
|
|
186
144
|
error: serialize(error),
|
|
187
|
-
type:
|
|
145
|
+
type: "uncaughtError" /* uncaughtError */
|
|
188
146
|
};
|
|
189
147
|
implementation.postMessageToMaster(errorMessage);
|
|
190
148
|
} catch (subError) {
|
|
191
|
-
console.error(
|
|
149
|
+
console.error(
|
|
150
|
+
"Not reporting uncaught error back to master thread as it occured while reporting an uncaught error already.\nLatest error:",
|
|
151
|
+
subError,
|
|
152
|
+
"\nOriginal error:",
|
|
153
|
+
error
|
|
154
|
+
);
|
|
192
155
|
}
|
|
193
156
|
}
|
|
194
|
-
__name(postUncaughtErrorMessage, "postUncaughtErrorMessage");
|
|
195
157
|
async function runFunction(jobUID, fn, args) {
|
|
196
158
|
let syncResult;
|
|
197
159
|
try {
|
|
@@ -203,13 +165,17 @@ function createExpose(implementation, self2) {
|
|
|
203
165
|
const resultType = isObservable(syncResult) ? "observable" : "promise";
|
|
204
166
|
postJobStartMessage(jobUID, resultType);
|
|
205
167
|
if (isObservable(syncResult)) {
|
|
206
|
-
const subscription = syncResult.subscribe(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
168
|
+
const subscription = syncResult.subscribe(
|
|
169
|
+
(value) => postJobResultMessage(jobUID, false, serialize(value)),
|
|
170
|
+
(error) => {
|
|
171
|
+
postJobErrorMessage(jobUID, serialize(error));
|
|
172
|
+
activeSubscriptions.delete(jobUID);
|
|
173
|
+
},
|
|
174
|
+
() => {
|
|
175
|
+
postJobResultMessage(jobUID, true);
|
|
176
|
+
activeSubscriptions.delete(jobUID);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
213
179
|
activeSubscriptions.set(jobUID, subscription);
|
|
214
180
|
} else {
|
|
215
181
|
try {
|
|
@@ -220,8 +186,7 @@ function createExpose(implementation, self2) {
|
|
|
220
186
|
}
|
|
221
187
|
}
|
|
222
188
|
}
|
|
223
|
-
|
|
224
|
-
const expose2 = /* @__PURE__ */ __name((exposed) => {
|
|
189
|
+
const expose2 = (exposed) => {
|
|
225
190
|
if (!implementation.isWorkerRuntime()) {
|
|
226
191
|
throw new Error("expose() called in the master thread.");
|
|
227
192
|
}
|
|
@@ -257,7 +222,7 @@ function createExpose(implementation, self2) {
|
|
|
257
222
|
}
|
|
258
223
|
}
|
|
259
224
|
});
|
|
260
|
-
}
|
|
225
|
+
};
|
|
261
226
|
if (typeof globalThis !== "undefined" && typeof self2.addEventListener === "function" && implementation.isWorkerRuntime()) {
|
|
262
227
|
self2.addEventListener("error", (event) => {
|
|
263
228
|
setTimeout(() => postUncaughtErrorMessage(isErrorEvent(event) ? event.error : event), 250);
|
|
@@ -281,26 +246,25 @@ function createExpose(implementation, self2) {
|
|
|
281
246
|
}
|
|
282
247
|
return expose2;
|
|
283
248
|
}
|
|
284
|
-
__name(createExpose, "createExpose");
|
|
285
249
|
|
|
286
250
|
// src/worker/worker.browser.ts
|
|
287
|
-
var isWorkerRuntime =
|
|
251
|
+
var isWorkerRuntime = function isWorkerRuntime2() {
|
|
288
252
|
const isWindowContext = self !== void 0 && typeof Window !== "undefined" && self instanceof Window;
|
|
289
253
|
return self !== void 0 && self["postMessage"] && !isWindowContext ? true : false;
|
|
290
|
-
}
|
|
291
|
-
var postMessageToMaster =
|
|
254
|
+
};
|
|
255
|
+
var postMessageToMaster = function postMessageToMaster2(data, transferList) {
|
|
292
256
|
self.postMessage(data, transferList);
|
|
293
|
-
}
|
|
294
|
-
var subscribeToMasterMessages =
|
|
295
|
-
const messageHandler =
|
|
257
|
+
};
|
|
258
|
+
var subscribeToMasterMessages = function subscribeToMasterMessages2(onMessage) {
|
|
259
|
+
const messageHandler = (messageEvent) => {
|
|
296
260
|
onMessage(messageEvent.data);
|
|
297
|
-
}
|
|
298
|
-
const unsubscribe =
|
|
261
|
+
};
|
|
262
|
+
const unsubscribe = () => {
|
|
299
263
|
self.removeEventListener("message", messageHandler);
|
|
300
|
-
}
|
|
264
|
+
};
|
|
301
265
|
self.addEventListener("message", messageHandler);
|
|
302
266
|
return unsubscribe;
|
|
303
|
-
}
|
|
267
|
+
};
|
|
304
268
|
var addEventListener = self.addEventListener.bind(void 0);
|
|
305
269
|
var postMessage = self.postMessage.bind(void 0);
|
|
306
270
|
var removeEventListener = self.removeEventListener.bind(void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/worker/expose.ts","../../../src/serializers.ts","../../../src/common.ts","../../../src/symbols.ts","../../../src/transferable.ts","../../../src/types/messages.ts","../../../src/worker/worker.browser.ts"],"sourcesContent":["/* eslint-disable import-x/no-internal-modules */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-floating-promises */\n\nimport isSomeObservable from 'is-observable-2-1-0'\nimport type { Observable, Subscription } from 'observable-fns'\n\nimport { deserialize, serialize } from '../common.ts'\nimport type { TransferDescriptor } from '../transferable.ts'\nimport { isTransferDescriptor } from '../transferable.ts'\nimport type {\n MasterJobCancelMessage,\n MasterJobRunMessage,\n SerializedError,\n WorkerInitMessage,\n WorkerJobErrorMessage,\n WorkerJobResultMessage,\n WorkerJobStartMessage,\n WorkerUncaughtErrorMessage,\n} from '../types/messages.ts'\nimport {\n MasterMessageType,\n WorkerMessageType,\n} from '../types/messages.ts'\nimport type {\n AbstractedWorkerAPI, WorkerFunction, WorkerModule,\n} from '../types/worker.ts'\nimport type { WorkerGlobalScope } from './WorkerGlobalScope.ts'\n\nconst isErrorEvent = (value: Event): value is ErrorEvent => value && (value as ErrorEvent).error\n\nexport function createExpose(implementation: AbstractedWorkerAPI, self: WorkerGlobalScope) {\n let exposeCalled = false\n\n const activeSubscriptions = new Map<number, Subscription<any>>()\n\n const isMasterJobCancelMessage = (thing: any): thing is MasterJobCancelMessage => thing && thing.type === MasterMessageType.cancel\n const isMasterJobRunMessage = (thing: any): thing is MasterJobRunMessage => thing && thing.type === MasterMessageType.run\n\n /**\n * There are issues with `is-observable` not recognizing zen-observable's instances.\n * We are using `observable-fns`, but it's based on zen-observable, too.\n */\n const isObservable = (thing: any): thing is Observable<any> => isSomeObservable(thing) || isZenObservable(thing)\n\n function isZenObservable(thing: any): thing is Observable<any> {\n return thing && typeof thing === 'object' && typeof thing.subscribe === 'function'\n }\n\n function deconstructTransfer(thing: any) {\n return isTransferDescriptor(thing) ? { payload: thing.send, transferables: thing.transferables } : { payload: thing, transferables: undefined }\n }\n\n function postFunctionInitMessage() {\n const initMessage: WorkerInitMessage = {\n exposed: { type: 'function' },\n type: WorkerMessageType.init,\n }\n implementation.postMessageToMaster(initMessage)\n }\n\n function postModuleInitMessage(methodNames: string[]) {\n const initMessage: WorkerInitMessage = {\n exposed: {\n methods: methodNames,\n type: 'module',\n },\n type: WorkerMessageType.init,\n }\n implementation.postMessageToMaster(initMessage)\n }\n\n function postJobErrorMessage(uid: number, rawError: Error | TransferDescriptor<Error>) {\n const { payload: error, transferables } = deconstructTransfer(rawError)\n const errorMessage: WorkerJobErrorMessage = {\n error: serialize(error) as any as SerializedError,\n type: WorkerMessageType.error,\n uid,\n }\n implementation.postMessageToMaster(errorMessage, transferables)\n }\n\n function postJobResultMessage(uid: number, completed: boolean, resultValue?: any) {\n const { payload, transferables } = deconstructTransfer(resultValue)\n const resultMessage: WorkerJobResultMessage = {\n complete: completed ? true : undefined,\n payload,\n type: WorkerMessageType.result,\n uid,\n }\n implementation.postMessageToMaster(resultMessage, transferables)\n }\n\n function postJobStartMessage(uid: number, resultType: WorkerJobStartMessage['resultType']) {\n const startMessage: WorkerJobStartMessage = {\n resultType,\n type: WorkerMessageType.running,\n uid,\n }\n implementation.postMessageToMaster(startMessage)\n }\n\n function postUncaughtErrorMessage(error: Error) {\n try {\n const errorMessage: WorkerUncaughtErrorMessage = {\n error: serialize(error) as any as SerializedError,\n type: WorkerMessageType.uncaughtError,\n }\n implementation.postMessageToMaster(errorMessage)\n } catch (subError) {\n // tslint:disable-next-line no-console\n console.error(\n 'Not reporting uncaught error back to master thread as it ' + 'occured while reporting an uncaught error already.' + '\\nLatest error:',\n subError,\n '\\nOriginal error:',\n error,\n )\n }\n }\n\n async function runFunction(jobUID: number, fn: WorkerFunction, args: any[]) {\n let syncResult: any\n\n try {\n syncResult = fn(...args)\n } catch (ex) {\n const error = ex as Error\n return postJobErrorMessage(jobUID, error)\n }\n\n const resultType = isObservable(syncResult) ? 'observable' : 'promise'\n postJobStartMessage(jobUID, resultType)\n\n if (isObservable(syncResult)) {\n const subscription = syncResult.subscribe(\n value => postJobResultMessage(jobUID, false, serialize(value)),\n (error) => {\n postJobErrorMessage(jobUID, serialize(error) as any)\n activeSubscriptions.delete(jobUID)\n },\n () => {\n postJobResultMessage(jobUID, true)\n activeSubscriptions.delete(jobUID)\n },\n )\n activeSubscriptions.set(jobUID, subscription)\n } else {\n try {\n const result = await syncResult\n postJobResultMessage(jobUID, true, serialize(result))\n } catch (error) {\n postJobErrorMessage(jobUID, serialize(error) as any)\n }\n }\n }\n\n /**\n * Expose a function or a module (an object whose values are functions)\n * to the main thread. Must be called exactly once in every worker thread\n * to signal its API to the main thread.\n *\n * @param exposed Function or object whose values are functions\n */\n const expose = (exposed: WorkerFunction | WorkerModule<any>) => {\n if (!implementation.isWorkerRuntime()) {\n throw new Error('expose() called in the master thread.')\n }\n if (exposeCalled) {\n throw new Error('expose() called more than once. This is not possible. Pass an object to expose() if you want to expose multiple functions.')\n }\n exposeCalled = true\n\n if (typeof exposed === 'function') {\n implementation.subscribeToMasterMessages((messageData: unknown) => {\n if (isMasterJobRunMessage(messageData) && !messageData.method) {\n runFunction(messageData.uid, exposed, messageData.args.map(deserialize))\n }\n })\n postFunctionInitMessage()\n } else if (typeof exposed === 'object' && exposed) {\n implementation.subscribeToMasterMessages((messageData: unknown) => {\n if (isMasterJobRunMessage(messageData) && messageData.method) {\n runFunction(messageData.uid, exposed[messageData.method], messageData.args.map(deserialize))\n }\n })\n\n const methodNames = Object.keys(exposed).filter(key => typeof exposed[key] === 'function')\n postModuleInitMessage(methodNames)\n } else {\n throw new Error(`Invalid argument passed to expose(). Expected a function or an object, got: ${exposed}`)\n }\n\n implementation.subscribeToMasterMessages((messageData: unknown) => {\n if (isMasterJobCancelMessage(messageData)) {\n const jobUID = messageData.uid\n const subscription = activeSubscriptions.get(jobUID)\n\n if (subscription) {\n subscription.unsubscribe()\n activeSubscriptions.delete(jobUID)\n }\n }\n })\n }\n\n if (typeof globalThis !== 'undefined' && typeof self.addEventListener === 'function' && implementation.isWorkerRuntime()) {\n self.addEventListener('error', (event) => {\n // Post with some delay, so the master had some time to subscribe to messages\n setTimeout(() => postUncaughtErrorMessage(isErrorEvent(event) ? event.error : event), 250)\n })\n self.addEventListener('unhandledrejection', (event) => {\n const error = (event as any).reason\n if (error && typeof (error as any).message === 'string') {\n // Post with some delay, so the master had some time to subscribe to messages\n setTimeout(() => postUncaughtErrorMessage(error), 250)\n }\n })\n }\n\n if (typeof process !== 'undefined' && typeof process.on === 'function' && implementation.isWorkerRuntime()) {\n process.on('uncaughtException', (error) => {\n // Post with some delay, so the master had some time to subscribe to messages\n setTimeout(() => postUncaughtErrorMessage(error), 250)\n })\n process.on('unhandledRejection', (error) => {\n if (error && typeof (error as any).message === 'string') {\n // Post with some delay, so the master had some time to subscribe to messages\n setTimeout(() => postUncaughtErrorMessage(error as any), 250)\n }\n })\n }\n\n return expose\n}\n","/* eslint-disable import-x/no-internal-modules */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { SerializedError } from './types/messages.ts'\n\nexport interface Serializer<Msg = JsonSerializable, Input = any> {\n deserialize(message: Msg): Input\n serialize(input: Input): Msg\n}\n\nexport interface SerializerImplementation<Msg = JsonSerializable, Input = any> {\n deserialize(message: Msg, defaultDeserialize: (msg: Msg) => Input): Input\n serialize(input: Input, defaultSerialize: (inp: Input) => Msg): Msg\n}\n\nexport function extendSerializer<MessageType, InputType = any>(\n extend: Serializer<MessageType, InputType>,\n implementation: SerializerImplementation<MessageType, InputType>,\n): Serializer<MessageType, InputType> {\n const fallbackDeserializer = extend.deserialize.bind(extend)\n const fallbackSerializer = extend.serialize.bind(extend)\n\n return {\n deserialize(message: MessageType): InputType {\n return implementation.deserialize(message, fallbackDeserializer)\n },\n\n serialize(input: InputType): MessageType {\n return implementation.serialize(input, fallbackSerializer)\n },\n }\n}\n\ntype JsonSerializablePrimitive = string | number | boolean | null\n\ntype JsonSerializableObject = {\n [key: string]: JsonSerializablePrimitive | JsonSerializablePrimitive[] | JsonSerializableObject | JsonSerializableObject[] | undefined\n}\n\nexport type JsonSerializable = JsonSerializablePrimitive | JsonSerializablePrimitive[] | JsonSerializableObject | JsonSerializableObject[]\n\nconst DefaultErrorSerializer: Serializer<SerializedError, Error> = {\n deserialize(message: SerializedError): Error {\n return Object.assign(new Error(message.message), {\n name: message.name,\n stack: message.stack,\n })\n },\n serialize(error: Error): SerializedError {\n return {\n __error_marker: '$$error',\n message: error.message,\n name: error.name,\n stack: error.stack,\n }\n },\n}\n\nconst isSerializedError = (thing: any): thing is SerializedError =>\n thing && typeof thing === 'object' && '__error_marker' in thing && thing.__error_marker === '$$error'\n\nexport const DefaultSerializer: Serializer<JsonSerializable> = {\n deserialize(message: JsonSerializable): any {\n return isSerializedError(message) ? DefaultErrorSerializer.deserialize(message) : message\n },\n serialize(input: any): JsonSerializable {\n return input instanceof Error ? (DefaultErrorSerializer.serialize(input) as any as JsonSerializable) : input\n },\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type {\n JsonSerializable, Serializer, SerializerImplementation,\n} from './serializers.ts'\nimport { DefaultSerializer, extendSerializer } from './serializers.ts'\n\ndeclare global {\n var registeredSerializer: Serializer<JsonSerializable>\n}\n\nglobalThis.registeredSerializer = globalThis.registeredSerializer ?? DefaultSerializer\n\nexport function registerSerializer(serializer: SerializerImplementation<JsonSerializable>) {\n globalThis.registeredSerializer = extendSerializer(globalThis.registeredSerializer, serializer)\n}\n\nexport function deserialize(message: JsonSerializable): any {\n return globalThis.registeredSerializer.deserialize(message)\n}\n\nexport function serialize(input: any): JsonSerializable {\n return globalThis.registeredSerializer.serialize(input)\n}\n","export const $errors = Symbol('thread.errors')\nexport const $events = Symbol('thread.events')\nexport const $terminate = Symbol('thread.terminate')\nexport const $transferable = Symbol('thread.transferable')\nexport const $worker = Symbol('thread.worker')\n","/// <reference lib=\"webworker\" />\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { $transferable } from './symbols.ts'\n\nexport interface TransferDescriptor<T = any> {\n [$transferable]: true\n send: T\n transferables: Transferable[]\n}\n\nfunction isTransferable(thing: any): thing is Transferable {\n if (!thing || typeof thing !== 'object') return false\n // Don't check too thoroughly, since the list of transferable things in JS might grow over time\n return true\n}\n\nexport function isTransferDescriptor(thing: any): thing is TransferDescriptor {\n return thing && typeof thing === 'object' && thing[$transferable]\n}\n\n/**\n * Mark a transferable object as such, so it will no be serialized and\n * deserialized on messaging with the main thread, but to transfer\n * ownership of it to the receiving thread.\n *\n * Only works with array buffers, message ports and few more special\n * types of objects, but it's much faster than serializing and\n * deserializing them.\n *\n * Note:\n * The transferable object cannot be accessed by this thread again\n * unless the receiving thread transfers it back again!\n *\n * @param transferable Array buffer, message port or similar.\n * @see <https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast>\n */\nexport function Transfer(transferable: Transferable): TransferDescriptor\n\n/**\n * Mark transferable objects within an arbitrary object or array as\n * being a transferable object. They will then not be serialized\n * and deserialized on messaging with the main thread, but ownership\n * of them will be tranferred to the receiving thread.\n *\n * Only array buffers, message ports and few more special types of\n * objects can be transferred, but it's much faster than serializing and\n * deserializing them.\n *\n * Note:\n * The transferable object cannot be accessed by this thread again\n * unless the receiving thread transfers it back again!\n *\n * @param transferable Array buffer, message port or similar.\n * @see <https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast>\n */\nexport function Transfer<T>(payload: T, transferables: Transferable[]): TransferDescriptor\n\nexport function Transfer<T>(payload: T, transferables?: Transferable[]): TransferDescriptor {\n console.log('Transfer')\n if (!transferables) {\n if (!isTransferable(payload)) throw new Error('Not transferable')\n transferables = [payload]\n }\n\n return {\n [$transferable]: true,\n send: payload,\n transferables,\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/member-ordering */\nexport interface SerializedError {\n __error_marker: '$$error'\n message: string\n name: string\n stack?: string\n}\n\n/////////////////////////////\n// Messages sent by master:\n\nexport enum MasterMessageType {\n cancel = 'cancel',\n run = 'run',\n}\n\nexport type MasterJobCancelMessage = {\n type: MasterMessageType.cancel\n uid: number\n}\n\nexport type MasterJobRunMessage = {\n type: MasterMessageType.run\n uid: number\n method?: string\n args: any[]\n}\n\n////////////////////////////\n// Messages sent by worker:\n\nexport enum WorkerMessageType {\n error = 'error',\n init = 'init',\n result = 'result',\n running = 'running',\n uncaughtError = 'uncaughtError',\n}\n\nexport type WorkerUncaughtErrorMessage = {\n type: WorkerMessageType.uncaughtError\n error: {\n message: string\n name: string\n stack?: string\n }\n}\n\nexport type WorkerInitMessage = {\n type: WorkerMessageType.init\n exposed: { type: 'function' } | { type: 'module'; methods: string[] }\n}\n\nexport type WorkerJobErrorMessage = {\n type: WorkerMessageType.error\n uid: number\n error: SerializedError\n}\n\nexport type WorkerJobResultMessage = {\n type: WorkerMessageType.result\n uid: number\n complete?: true\n payload?: any\n}\n\nexport type WorkerJobStartMessage = {\n type: WorkerMessageType.running\n uid: number\n resultType: 'observable' | 'promise'\n}\n","/* eslint-disable import-x/no-internal-modules */\n\n/// <reference lib=\"dom\" />\n// tslint:disable no-shadowed-variable\n\nimport type { AbstractedWorkerAPI } from '../types/worker.ts'\nimport { createExpose } from './expose.ts'\nimport type { WorkerGlobalScope } from './WorkerGlobalScope.ts'\n\ndeclare const self: WorkerGlobalScope\n\nconst isWorkerRuntime: AbstractedWorkerAPI['isWorkerRuntime'] = function isWorkerRuntime() {\n const isWindowContext = self !== undefined && typeof Window !== 'undefined' && self instanceof Window\n return self !== undefined && self['postMessage'] && !isWindowContext ? true : false\n}\n\nconst postMessageToMaster: AbstractedWorkerAPI['postMessageToMaster'] = function postMessageToMaster(data, transferList?) {\n self.postMessage(data, transferList)\n}\n\nconst subscribeToMasterMessages: AbstractedWorkerAPI['subscribeToMasterMessages'] = function subscribeToMasterMessages(onMessage) {\n const messageHandler = (messageEvent: MessageEvent) => {\n onMessage(messageEvent.data)\n }\n const unsubscribe = () => {\n self.removeEventListener('message', messageHandler as EventListener)\n }\n self.addEventListener('message', messageHandler as EventListener)\n return unsubscribe\n}\n\nconst addEventListener = self.addEventListener.bind(this)\nconst postMessage = self.postMessage.bind(this)\nconst removeEventListener = self.removeEventListener.bind(this)\n\nexport {\n addEventListener,\n postMessage,\n removeEventListener,\n}\n\nconst expose = createExpose({\n isWorkerRuntime, postMessageToMaster, subscribeToMasterMessages,\n}, {\n addEventListener, postMessage, removeEventListener,\n})\n\nexport {\n isWorkerRuntime,\n postMessageToMaster,\n subscribeToMasterMessages,\n}\n\nexport { registerSerializer } from '../common.ts'\nexport { Transfer } from '../transferable.ts'\nexport { expose }\n"],"mappings":";;;;AAIA,OAAOA,sBAAsB;;;ACUtB,SAASC,iBACdC,QACAC,gBAAgE;AAEhE,QAAMC,uBAAuBF,OAAOG,YAAYC,KAAKJ,MAAAA;AACrD,QAAMK,qBAAqBL,OAAOM,UAAUF,KAAKJ,MAAAA;AAEjD,SAAO;IACLG,YAAYI,SAAoB;AAC9B,aAAON,eAAeE,YAAYI,SAASL,oBAAAA;IAC7C;IAEAI,UAAUE,OAAgB;AACxB,aAAOP,eAAeK,UAAUE,OAAOH,kBAAAA;IACzC;EACF;AACF;AAhBgBN;AA0BhB,IAAMU,yBAA6D;EACjEN,YAAYI,SAAwB;AAClC,WAAOG,OAAOC,OAAO,IAAIC,MAAML,QAAQA,OAAO,GAAG;MAC/CM,MAAMN,QAAQM;MACdC,OAAOP,QAAQO;IACjB,CAAA;EACF;EACAR,UAAUS,OAAY;AACpB,WAAO;MACLC,gBAAgB;MAChBT,SAASQ,MAAMR;MACfM,MAAME,MAAMF;MACZC,OAAOC,MAAMD;IACf;EACF;AACF;AAEA,IAAMG,oBAAoB,wBAACC,UACzBA,SAAS,OAAOA,UAAU,YAAY,oBAAoBA,SAASA,MAAMF,mBAAmB,WADpE;AAGnB,IAAMG,oBAAkD;EAC7DhB,YAAYI,SAAyB;AACnC,WAAOU,kBAAkBV,OAAAA,IAAWE,uBAAuBN,YAAYI,OAAAA,IAAWA;EACpF;EACAD,UAAUE,OAAU;AAClB,WAAOA,iBAAiBI,QAASH,uBAAuBH,UAAUE,KAAAA,IAAqCA;EACzG;AACF;;;ACzDAY,WAAWC,uBAAuBD,WAAWC,wBAAwBC;AAE9D,SAASC,mBAAmBC,YAAsD;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,cAAc,6BAAA;AAClBX,SAAKY,oBAAoB,WAAWH,cAAAA;EACtC,GAFoB;AAGpBT,OAAKa,iBAAiB,WAAWJ,cAAAA;AACjC,SAAOE;AACT,GAToF;AAWpF,IAAME,mBAAmBb,KAAKa,iBAAiBC,KAAK,MAAI;AACxD,IAAMR,cAAcN,KAAKM,YAAYQ,KAAK,MAAI;AAC9C,IAAMF,sBAAsBZ,KAAKY,oBAAoBE,KAAK,MAAI;AAQ9D,IAAMC,SAASC,aAAa;EAC1BC;EAAiBC;EAAqBC;AACxC,GAAG;EACDC;EAAkBC;EAAaC;AACjC,CAAA;","names":["isSomeObservable","extendSerializer","extend","implementation","fallbackDeserializer","deserialize","bind","fallbackSerializer","serialize","message","input","DefaultErrorSerializer","Object","assign","Error","name","stack","error","__error_marker","isSerializedError","thing","DefaultSerializer","globalThis","registeredSerializer","DefaultSerializer","registerSerializer","serializer","extendSerializer","deserialize","message","serialize","input","$errors","Symbol","$events","$terminate","$transferable","$worker","isTransferable","thing","isTransferDescriptor","$transferable","Transfer","payload","transferables","console","log","Error","send","MasterMessageType","WorkerMessageType","isErrorEvent","value","error","createExpose","implementation","self","exposeCalled","activeSubscriptions","Map","isMasterJobCancelMessage","thing","type","MasterMessageType","cancel","isMasterJobRunMessage","run","isObservable","isSomeObservable","isZenObservable","subscribe","deconstructTransfer","isTransferDescriptor","payload","send","transferables","undefined","postFunctionInitMessage","initMessage","exposed","WorkerMessageType","init","postMessageToMaster","postModuleInitMessage","methodNames","methods","postJobErrorMessage","uid","rawError","errorMessage","serialize","postJobResultMessage","completed","resultValue","resultMessage","complete","result","postJobStartMessage","resultType","startMessage","running","postUncaughtErrorMessage","uncaughtError","subError","console","runFunction","jobUID","fn","args","syncResult","ex","subscription","delete","set","expose","isWorkerRuntime","Error","subscribeToMasterMessages","messageData","method","map","deserialize","Object","keys","filter","key","get","unsubscribe","globalThis","addEventListener","event","setTimeout","reason","message","process","on","isWorkerRuntime","isWindowContext","self","undefined","Window","postMessageToMaster","data","transferList","postMessage","subscribeToMasterMessages","onMessage","messageHandler","messageEvent","unsubscribe","removeEventListener","addEventListener","bind","expose","createExpose","isWorkerRuntime","postMessageToMaster","subscribeToMasterMessages","addEventListener","postMessage","removeEventListener"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/worker/expose.ts","../../../src/serializers.ts","../../../src/common.ts","../../../src/symbols.ts","../../../src/transferable.ts","../../../src/worker/worker.browser.ts"],"sourcesContent":["/* eslint-disable import-x/no-internal-modules */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-floating-promises */\n\nimport isSomeObservable from 'is-observable-2-1-0'\nimport type { Observable, Subscription } from 'observable-fns'\n\nimport { deserialize, serialize } from '../common.ts'\nimport type { TransferDescriptor } from '../transferable.ts'\nimport { isTransferDescriptor } from '../transferable.ts'\nimport type {\n MasterJobCancelMessage,\n MasterJobRunMessage,\n SerializedError,\n WorkerInitMessage,\n WorkerJobErrorMessage,\n WorkerJobResultMessage,\n WorkerJobStartMessage,\n WorkerUncaughtErrorMessage,\n} from '../types/messages.ts'\nimport {\n MasterMessageType,\n WorkerMessageType,\n} from '../types/messages.ts'\nimport type {\n AbstractedWorkerAPI, WorkerFunction, WorkerModule,\n} from '../types/worker.ts'\nimport type { WorkerGlobalScope } from './WorkerGlobalScope.ts'\n\nconst isErrorEvent = (value: Event): value is ErrorEvent => value && (value as ErrorEvent).error\n\nexport function createExpose(implementation: AbstractedWorkerAPI, self: WorkerGlobalScope) {\n let exposeCalled = false\n\n const activeSubscriptions = new Map<number, Subscription<any>>()\n\n const isMasterJobCancelMessage = (thing: any): thing is MasterJobCancelMessage => thing && thing.type === MasterMessageType.cancel\n const isMasterJobRunMessage = (thing: any): thing is MasterJobRunMessage => thing && thing.type === MasterMessageType.run\n\n /**\n * There are issues with `is-observable` not recognizing zen-observable's instances.\n * We are using `observable-fns`, but it's based on zen-observable, too.\n */\n const isObservable = (thing: any): thing is Observable<any> => isSomeObservable(thing) || isZenObservable(thing)\n\n function isZenObservable(thing: any): thing is Observable<any> {\n return thing && typeof thing === 'object' && typeof thing.subscribe === 'function'\n }\n\n function deconstructTransfer(thing: any) {\n return isTransferDescriptor(thing) ? { payload: thing.send, transferables: thing.transferables } : { payload: thing, transferables: undefined }\n }\n\n function postFunctionInitMessage() {\n const initMessage: WorkerInitMessage = {\n exposed: { type: 'function' },\n type: WorkerMessageType.init,\n }\n implementation.postMessageToMaster(initMessage)\n }\n\n function postModuleInitMessage(methodNames: string[]) {\n const initMessage: WorkerInitMessage = {\n exposed: {\n methods: methodNames,\n type: 'module',\n },\n type: WorkerMessageType.init,\n }\n implementation.postMessageToMaster(initMessage)\n }\n\n function postJobErrorMessage(uid: number, rawError: Error | TransferDescriptor<Error>) {\n const { payload: error, transferables } = deconstructTransfer(rawError)\n const errorMessage: WorkerJobErrorMessage = {\n error: serialize(error) as any as SerializedError,\n type: WorkerMessageType.error,\n uid,\n }\n implementation.postMessageToMaster(errorMessage, transferables)\n }\n\n function postJobResultMessage(uid: number, completed: boolean, resultValue?: any) {\n const { payload, transferables } = deconstructTransfer(resultValue)\n const resultMessage: WorkerJobResultMessage = {\n complete: completed ? true : undefined,\n payload,\n type: WorkerMessageType.result,\n uid,\n }\n implementation.postMessageToMaster(resultMessage, transferables)\n }\n\n function postJobStartMessage(uid: number, resultType: WorkerJobStartMessage['resultType']) {\n const startMessage: WorkerJobStartMessage = {\n resultType,\n type: WorkerMessageType.running,\n uid,\n }\n implementation.postMessageToMaster(startMessage)\n }\n\n function postUncaughtErrorMessage(error: Error) {\n try {\n const errorMessage: WorkerUncaughtErrorMessage = {\n error: serialize(error) as any as SerializedError,\n type: WorkerMessageType.uncaughtError,\n }\n implementation.postMessageToMaster(errorMessage)\n } catch (subError) {\n // tslint:disable-next-line no-console\n console.error(\n 'Not reporting uncaught error back to master thread as it ' + 'occured while reporting an uncaught error already.' + '\\nLatest error:',\n subError,\n '\\nOriginal error:',\n error,\n )\n }\n }\n\n async function runFunction(jobUID: number, fn: WorkerFunction, args: any[]) {\n let syncResult: any\n\n try {\n syncResult = fn(...args)\n } catch (ex) {\n const error = ex as Error\n return postJobErrorMessage(jobUID, error)\n }\n\n const resultType = isObservable(syncResult) ? 'observable' : 'promise'\n postJobStartMessage(jobUID, resultType)\n\n if (isObservable(syncResult)) {\n const subscription = syncResult.subscribe(\n value => postJobResultMessage(jobUID, false, serialize(value)),\n (error) => {\n postJobErrorMessage(jobUID, serialize(error) as any)\n activeSubscriptions.delete(jobUID)\n },\n () => {\n postJobResultMessage(jobUID, true)\n activeSubscriptions.delete(jobUID)\n },\n )\n activeSubscriptions.set(jobUID, subscription)\n } else {\n try {\n const result = await syncResult\n postJobResultMessage(jobUID, true, serialize(result))\n } catch (error) {\n postJobErrorMessage(jobUID, serialize(error) as any)\n }\n }\n }\n\n /**\n * Expose a function or a module (an object whose values are functions)\n * to the main thread. Must be called exactly once in every worker thread\n * to signal its API to the main thread.\n *\n * @param exposed Function or object whose values are functions\n */\n const expose = (exposed: WorkerFunction | WorkerModule<any>) => {\n if (!implementation.isWorkerRuntime()) {\n throw new Error('expose() called in the master thread.')\n }\n if (exposeCalled) {\n throw new Error('expose() called more than once. This is not possible. Pass an object to expose() if you want to expose multiple functions.')\n }\n exposeCalled = true\n\n if (typeof exposed === 'function') {\n implementation.subscribeToMasterMessages((messageData: unknown) => {\n if (isMasterJobRunMessage(messageData) && !messageData.method) {\n runFunction(messageData.uid, exposed, messageData.args.map(deserialize))\n }\n })\n postFunctionInitMessage()\n } else if (typeof exposed === 'object' && exposed) {\n implementation.subscribeToMasterMessages((messageData: unknown) => {\n if (isMasterJobRunMessage(messageData) && messageData.method) {\n runFunction(messageData.uid, exposed[messageData.method], messageData.args.map(deserialize))\n }\n })\n\n const methodNames = Object.keys(exposed).filter(key => typeof exposed[key] === 'function')\n postModuleInitMessage(methodNames)\n } else {\n throw new Error(`Invalid argument passed to expose(). Expected a function or an object, got: ${exposed}`)\n }\n\n implementation.subscribeToMasterMessages((messageData: unknown) => {\n if (isMasterJobCancelMessage(messageData)) {\n const jobUID = messageData.uid\n const subscription = activeSubscriptions.get(jobUID)\n\n if (subscription) {\n subscription.unsubscribe()\n activeSubscriptions.delete(jobUID)\n }\n }\n })\n }\n\n if (typeof globalThis !== 'undefined' && typeof self.addEventListener === 'function' && implementation.isWorkerRuntime()) {\n self.addEventListener('error', (event) => {\n // Post with some delay, so the master had some time to subscribe to messages\n setTimeout(() => postUncaughtErrorMessage(isErrorEvent(event) ? event.error : event), 250)\n })\n self.addEventListener('unhandledrejection', (event) => {\n const error = (event as any).reason\n if (error && typeof (error as any).message === 'string') {\n // Post with some delay, so the master had some time to subscribe to messages\n setTimeout(() => postUncaughtErrorMessage(error), 250)\n }\n })\n }\n\n if (typeof process !== 'undefined' && typeof process.on === 'function' && implementation.isWorkerRuntime()) {\n process.on('uncaughtException', (error) => {\n // Post with some delay, so the master had some time to subscribe to messages\n setTimeout(() => postUncaughtErrorMessage(error), 250)\n })\n process.on('unhandledRejection', (error) => {\n if (error && typeof (error as any).message === 'string') {\n // Post with some delay, so the master had some time to subscribe to messages\n setTimeout(() => postUncaughtErrorMessage(error as any), 250)\n }\n })\n }\n\n return expose\n}\n","/* eslint-disable import-x/no-internal-modules */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { SerializedError } from './types/messages.ts'\n\nexport interface Serializer<Msg = JsonSerializable, Input = any> {\n deserialize(message: Msg): Input\n serialize(input: Input): Msg\n}\n\nexport interface SerializerImplementation<Msg = JsonSerializable, Input = any> {\n deserialize(message: Msg, defaultDeserialize: (msg: Msg) => Input): Input\n serialize(input: Input, defaultSerialize: (inp: Input) => Msg): Msg\n}\n\nexport function extendSerializer<MessageType, InputType = any>(\n extend: Serializer<MessageType, InputType>,\n implementation: SerializerImplementation<MessageType, InputType>,\n): Serializer<MessageType, InputType> {\n const fallbackDeserializer = extend.deserialize.bind(extend)\n const fallbackSerializer = extend.serialize.bind(extend)\n\n return {\n deserialize(message: MessageType): InputType {\n return implementation.deserialize(message, fallbackDeserializer)\n },\n\n serialize(input: InputType): MessageType {\n return implementation.serialize(input, fallbackSerializer)\n },\n }\n}\n\ntype JsonSerializablePrimitive = string | number | boolean | null\n\ntype JsonSerializableObject = {\n [key: string]: JsonSerializablePrimitive | JsonSerializablePrimitive[] | JsonSerializableObject | JsonSerializableObject[] | undefined\n}\n\nexport type JsonSerializable = JsonSerializablePrimitive | JsonSerializablePrimitive[] | JsonSerializableObject | JsonSerializableObject[]\n\nconst DefaultErrorSerializer: Serializer<SerializedError, Error> = {\n deserialize(message: SerializedError): Error {\n return Object.assign(new Error(message.message), {\n name: message.name,\n stack: message.stack,\n })\n },\n serialize(error: Error): SerializedError {\n return {\n __error_marker: '$$error',\n message: error.message,\n name: error.name,\n stack: error.stack,\n }\n },\n}\n\nconst isSerializedError = (thing: any): thing is SerializedError =>\n thing && typeof thing === 'object' && '__error_marker' in thing && thing.__error_marker === '$$error'\n\nexport const DefaultSerializer: Serializer<JsonSerializable> = {\n deserialize(message: JsonSerializable): any {\n return isSerializedError(message) ? DefaultErrorSerializer.deserialize(message) : message\n },\n serialize(input: any): JsonSerializable {\n return input instanceof Error ? (DefaultErrorSerializer.serialize(input) as any as JsonSerializable) : input\n },\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type {\n JsonSerializable, Serializer, SerializerImplementation,\n} from './serializers.ts'\nimport { DefaultSerializer, extendSerializer } from './serializers.ts'\n\ndeclare global {\n var registeredSerializer: Serializer<JsonSerializable>\n}\n\nglobalThis.registeredSerializer = globalThis.registeredSerializer ?? DefaultSerializer\n\nexport function registerSerializer(serializer: SerializerImplementation<JsonSerializable>) {\n globalThis.registeredSerializer = extendSerializer(globalThis.registeredSerializer, serializer)\n}\n\nexport function deserialize(message: JsonSerializable): any {\n return globalThis.registeredSerializer.deserialize(message)\n}\n\nexport function serialize(input: any): JsonSerializable {\n return globalThis.registeredSerializer.serialize(input)\n}\n","export const $errors = Symbol('thread.errors')\nexport const $events = Symbol('thread.events')\nexport const $terminate = Symbol('thread.terminate')\nexport const $transferable = Symbol('thread.transferable')\nexport const $worker = Symbol('thread.worker')\n","/// <reference lib=\"webworker\" />\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { $transferable } from './symbols.ts'\n\nexport interface TransferDescriptor<T = any> {\n [$transferable]: true\n send: T\n transferables: Transferable[]\n}\n\nfunction isTransferable(thing: any): thing is Transferable {\n if (!thing || typeof thing !== 'object') return false\n // Don't check too thoroughly, since the list of transferable things in JS might grow over time\n return true\n}\n\nexport function isTransferDescriptor(thing: any): thing is TransferDescriptor {\n return thing && typeof thing === 'object' && thing[$transferable]\n}\n\n/**\n * Mark a transferable object as such, so it will no be serialized and\n * deserialized on messaging with the main thread, but to transfer\n * ownership of it to the receiving thread.\n *\n * Only works with array buffers, message ports and few more special\n * types of objects, but it's much faster than serializing and\n * deserializing them.\n *\n * Note:\n * The transferable object cannot be accessed by this thread again\n * unless the receiving thread transfers it back again!\n *\n * @param transferable Array buffer, message port or similar.\n * @see <https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast>\n */\nexport function Transfer(transferable: Transferable): TransferDescriptor\n\n/**\n * Mark transferable objects within an arbitrary object or array as\n * being a transferable object. They will then not be serialized\n * and deserialized on messaging with the main thread, but ownership\n * of them will be tranferred to the receiving thread.\n *\n * Only array buffers, message ports and few more special types of\n * objects can be transferred, but it's much faster than serializing and\n * deserializing them.\n *\n * Note:\n * The transferable object cannot be accessed by this thread again\n * unless the receiving thread transfers it back again!\n *\n * @param transferable Array buffer, message port or similar.\n * @see <https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast>\n */\nexport function Transfer<T>(payload: T, transferables: Transferable[]): TransferDescriptor\n\nexport function Transfer<T>(payload: T, transferables?: Transferable[]): TransferDescriptor {\n console.log('Transfer')\n if (!transferables) {\n if (!isTransferable(payload)) throw new Error('Not transferable')\n transferables = [payload]\n }\n\n return {\n [$transferable]: true,\n send: payload,\n transferables,\n }\n}\n","/* eslint-disable import-x/no-internal-modules */\n\n/// <reference lib=\"dom\" />\n// tslint:disable no-shadowed-variable\n\nimport type { AbstractedWorkerAPI } from '../types/worker.ts'\nimport { createExpose } from './expose.ts'\nimport type { WorkerGlobalScope } from './WorkerGlobalScope.ts'\n\ndeclare const self: WorkerGlobalScope\n\nconst isWorkerRuntime: AbstractedWorkerAPI['isWorkerRuntime'] = function isWorkerRuntime() {\n const isWindowContext = self !== undefined && typeof Window !== 'undefined' && self instanceof Window\n return self !== undefined && self['postMessage'] && !isWindowContext ? true : false\n}\n\nconst postMessageToMaster: AbstractedWorkerAPI['postMessageToMaster'] = function postMessageToMaster(data, transferList?) {\n self.postMessage(data, transferList)\n}\n\nconst subscribeToMasterMessages: AbstractedWorkerAPI['subscribeToMasterMessages'] = function subscribeToMasterMessages(onMessage) {\n const messageHandler = (messageEvent: MessageEvent) => {\n onMessage(messageEvent.data)\n }\n const unsubscribe = () => {\n self.removeEventListener('message', messageHandler as EventListener)\n }\n self.addEventListener('message', messageHandler as EventListener)\n return unsubscribe\n}\n\nconst addEventListener = self.addEventListener.bind(this)\nconst postMessage = self.postMessage.bind(this)\nconst removeEventListener = self.removeEventListener.bind(this)\n\nexport {\n addEventListener,\n postMessage,\n removeEventListener,\n}\n\nconst expose = createExpose({\n isWorkerRuntime, postMessageToMaster, subscribeToMasterMessages,\n}, {\n addEventListener, postMessage, removeEventListener,\n})\n\nexport {\n isWorkerRuntime,\n postMessageToMaster,\n subscribeToMasterMessages,\n}\n\nexport { registerSerializer } from '../common.ts'\nexport { Transfer } from '../transferable.ts'\nexport { expose }\n"],"mappings":";AAIA,OAAO,sBAAsB;;;ACUtB,SAAS,iBACd,QACA,gBACoC;AACpC,QAAM,uBAAuB,OAAO,YAAY,KAAK,MAAM;AAC3D,QAAM,qBAAqB,OAAO,UAAU,KAAK,MAAM;AAEvD,SAAO;AAAA,IACL,YAAY,SAAiC;AAC3C,aAAO,eAAe,YAAY,SAAS,oBAAoB;A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