@xylabs/threads 5.0.82 → 5.0.84
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/README.md +29 -1
- package/dist/browser/{common-Cuiya5FG.d.ts → common-C73XWm6T.d.ts} +8 -0
- package/dist/browser/{index-browser-CZc9d-db.d.ts → index-browser-CaVWHLzx.d.ts} +3 -2
- package/dist/browser/index-browser.d.ts +5 -5
- package/dist/browser/index-browser.mjs.map +1 -1
- package/dist/browser/master/implementation.browser.d.ts +11 -2
- package/dist/browser/master/implementation.browser.mjs.map +1 -1
- package/dist/browser/master/index-browser.d.ts +4 -4
- package/dist/browser/master/index-browser.mjs.map +1 -1
- package/dist/browser/master/pool-browser.d.ts +4 -2
- package/dist/browser/master/pool-browser.mjs.map +1 -1
- package/dist/browser/{master-CFxtmoRJ.d.ts → master-tsvhUhUx.d.ts} +15 -1
- package/dist/{node/transferable-BjEBIWqm.d.ts → browser/transferable-sfmQXy9d.d.ts} +6 -0
- package/dist/browser/worker/worker.browser.d.ts +9 -3
- package/dist/browser/worker/worker.browser.mjs.map +1 -1
- package/dist/browser/{worker-04t9iwDh.d.ts → worker-DW4hSCsH.d.ts} +3 -0
- package/dist/neutral/master/register.mjs.map +1 -1
- package/dist/neutral/master/spawn.d.ts +4 -1
- package/dist/neutral/master/spawn.mjs.map +1 -1
- package/dist/neutral/master/thread.d.ts +2 -1
- package/dist/neutral/master/thread.mjs.map +1 -1
- package/dist/neutral/{master-BaKB0oWh.d.ts → master-4pyGz_8-.d.ts} +18 -0
- package/dist/neutral/observable.d.ts +3 -0
- package/dist/neutral/observable.mjs +3 -0
- package/dist/neutral/observable.mjs.map +1 -1
- package/dist/neutral/types/messages.d.ts +10 -0
- package/dist/neutral/types/messages.mjs.map +1 -1
- package/dist/node/{common-Cuiya5FG.d.ts → common-C73XWm6T.d.ts} +8 -0
- package/dist/node/{index-node-BjbCKNdn.d.ts → index-node-DqmfxCpi.d.ts} +4 -3
- package/dist/node/index-node.d.ts +6 -6
- package/dist/node/index-node.mjs.map +1 -1
- package/dist/node/master/implementation.node.d.ts +11 -2
- package/dist/node/master/implementation.node.mjs.map +1 -1
- package/dist/node/master/index-node.d.ts +5 -5
- package/dist/node/master/index-node.mjs.map +1 -1
- package/dist/node/master/pool-node.d.ts +3 -3
- package/dist/node/master/pool-node.mjs.map +1 -1
- package/dist/node/{master-CTbq2uzL.d.ts → master-CUiPpMI3.d.ts} +15 -1
- package/dist/node/{pool-types-CTBjm1B2.d.ts → pool-types-Ay463MW0.d.ts} +3 -1
- package/dist/{browser/transferable-BjEBIWqm.d.ts → node/transferable-sfmQXy9d.d.ts} +6 -0
- package/dist/node/worker/worker.node.d.ts +9 -3
- package/dist/node/worker/worker.node.mjs.map +1 -1
- package/dist/node/{worker-04t9iwDh.d.ts → worker-DW4hSCsH.d.ts} +3 -0
- package/package.json +5 -5
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
/** Symbol key for accessing a thread's error observable. */
|
|
1
2
|
declare const $errors: unique symbol;
|
|
3
|
+
/** Symbol key for accessing a thread's event observable. */
|
|
2
4
|
declare const $events: unique symbol;
|
|
5
|
+
/** Symbol key for accessing a thread's terminate function. */
|
|
3
6
|
declare const $terminate: unique symbol;
|
|
7
|
+
/** Symbol key for marking an object as a transferable descriptor. */
|
|
4
8
|
declare const $transferable: unique symbol;
|
|
9
|
+
/** Symbol key for accessing the underlying worker instance of a thread. */
|
|
5
10
|
declare const $worker: unique symbol;
|
|
6
11
|
|
|
12
|
+
/** Descriptor wrapping a value with its associated transferable objects for zero-copy messaging. */
|
|
7
13
|
interface TransferDescriptor<T = any> {
|
|
8
14
|
[$transferable]: true;
|
|
9
15
|
send: T;
|
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
import { W as WorkerFunction, a as WorkerModule, A as AbstractedWorkerAPI } from '../worker-
|
|
1
|
+
import { W as WorkerFunction, a as WorkerModule, A as AbstractedWorkerAPI } from '../worker-DW4hSCsH.js';
|
|
2
2
|
import * as node_worker_threads from 'node:worker_threads';
|
|
3
3
|
import { MessagePort } from 'node:worker_threads';
|
|
4
|
-
export { r as registerSerializer } from '../common-
|
|
5
|
-
export { T as Transfer } from '../transferable-
|
|
4
|
+
export { r as registerSerializer } from '../common-C73XWm6T.js';
|
|
5
|
+
export { T as Transfer } from '../transferable-sfmQXy9d.js';
|
|
6
6
|
|
|
7
|
+
/** Check if the current code is running inside a Node.js worker thread. */
|
|
7
8
|
declare const isWorkerRuntime: AbstractedWorkerAPI['isWorkerRuntime'];
|
|
9
|
+
/** Post a message from this worker to the master thread via the parent port. */
|
|
8
10
|
declare const postMessageToMaster: AbstractedWorkerAPI['postMessageToMaster'];
|
|
11
|
+
/** Subscribe to messages from the master thread on the parent port. */
|
|
9
12
|
declare const subscribeToMasterMessages: AbstractedWorkerAPI['subscribeToMasterMessages'];
|
|
13
|
+
/** Bound `on` method from the parent port for adding event listeners. */
|
|
10
14
|
declare const addEventListener: {
|
|
11
15
|
(event: "close", listener: (ev: Event) => void): MessagePort;
|
|
12
16
|
(event: "message", listener: (value: any) => void): MessagePort;
|
|
13
17
|
(event: "messageerror", listener: (error: Error) => void): MessagePort;
|
|
14
18
|
(event: string, listener: (arg: any) => void): MessagePort;
|
|
15
19
|
};
|
|
20
|
+
/** Bound `postMessage` method from the parent port. */
|
|
16
21
|
declare const postMessage: {
|
|
17
22
|
(message: any, transfer: node_worker_threads.Transferable[]): void;
|
|
18
23
|
(message: any, options?: node_worker_threads.StructuredSerializeOptions): void;
|
|
19
24
|
};
|
|
25
|
+
/** Bound `off` method from the parent port for removing event listeners. */
|
|
20
26
|
declare const removeEventListener: {
|
|
21
27
|
(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): MessagePort;
|
|
22
28
|
(event: "message", listener: (value: any) => void, options?: EventListenerOptions): MessagePort;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/worker/worker.node.ts","../../../src/worker/expose.ts","../../../src/serializers.ts","../../../src/common.ts","../../../src/symbols.ts","../../../src/transferable.ts"],"sourcesContent":["/* eslint-disable import-x/no-internal-modules */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// tslint:disable no-shadowed-variable\n\nimport type { MessagePort, TransferListItem } from 'node:worker_threads'\nimport { parentPort as optionalParentPort } from 'node:worker_threads'\n\nimport { assertEx } from '@xylabs/assert'\n\nimport type { AbstractedWorkerAPI } from '../types/worker.ts'\nimport { createExpose } from './expose.ts'\n\nconst parentPort = assertEx(optionalParentPort, () => 'Invariant violation: MessagePort to parent is not available.')\n\nfunction assertMessagePort(port: MessagePort | null | undefined): MessagePort {\n if (!port) {\n throw new Error('Invariant violation: MessagePort to parent is not available.')\n }\n return port\n}\n\nconst isWorkerRuntime: AbstractedWorkerAPI['isWorkerRuntime'] = function isWorkerRuntime() {\n return true // isMainThread\n}\n\nconst postMessageToMaster: AbstractedWorkerAPI['postMessageToMaster'] = function postMessageToMaster(data, transferList) {\n assertMessagePort(parentPort).postMessage(data, transferList as TransferListItem[])\n}\n\nconst subscribeToMasterMessages: AbstractedWorkerAPI['subscribeToMasterMessages'] = function subscribeToMasterMessages(onMessage) {\n if (!parentPort) {\n throw new Error('Invariant violation: MessagePort to parent is not available.')\n }\n const messageHandler = (message: any) => {\n onMessage(message)\n }\n const unsubscribe = () => {\n assertMessagePort(parentPort).off('message', messageHandler)\n }\n assertMessagePort(parentPort).on('message', messageHandler)\n return unsubscribe\n}\n\nconst addEventListener = parentPort?.on.bind(parentPort)\nconst postMessage = parentPort?.postMessage.bind(parentPort)\nconst removeEventListener = parentPort?.off.bind(parentPort)\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","/* 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"],"mappings":";AAKA,SAAS,cAAc,0BAA0B;AAEjD,SAAS,gBAAgB;;;ACHzB,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,eAA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AM,YAAkC;AACpF;AAEA,IAAM,4BAA8E,SAASC,2BAA0B,WAAW;AAChI,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,8DAA8D;AAAA,EAChF;AACA,QAAM,iBAAiB,CAAC,YAAiB;AACvC,cAAU,OAAO;AAAA,EACnB;AACA,QAAM,cAAc,MAAM;AACxB,sBAAkB,UAAU,EAAE,IAAI,WAAW,cAAc;AAAA,EAC7D;AACA,oBAAkB,UAAU,EAAE,GAAG,WAAW,cAAc;AAC1D,SAAO;AACT;AAEA,IAAM,mBAAmB,YAAY,GAAG,KAAK,UAAU;AACvD,IAAM,cAAc,YAAY,YAAY,KAAK,UAAU;AAC3D,IAAM,sBAAsB,YAAY,IAAI,KAAK,UAAU;AAQ3D,IAAM,SAAS,aAAa;AAAA,EAC1B;AAAA,EAAiB;AAAA,EAAqB;AACxC,GAAG;AAAA,EACD;AAAA,EAAkB;AAAA,EAAa;AACjC,CAAC;","names":["expose","isWorkerRuntime","postMessageToMaster","subscribeToMasterMessages"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/worker/worker.node.ts","../../../src/worker/expose.ts","../../../src/serializers.ts","../../../src/common.ts","../../../src/symbols.ts","../../../src/transferable.ts"],"sourcesContent":["/* eslint-disable import-x/no-internal-modules */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// tslint:disable no-shadowed-variable\n\nimport type { MessagePort, TransferListItem } from 'node:worker_threads'\nimport { parentPort as optionalParentPort } from 'node:worker_threads'\n\nimport { assertEx } from '@xylabs/assert'\n\nimport type { AbstractedWorkerAPI } from '../types/worker.ts'\nimport { createExpose } from './expose.ts'\n\nconst parentPort = assertEx(optionalParentPort, () => 'Invariant violation: MessagePort to parent is not available.')\n\nfunction assertMessagePort(port: MessagePort | null | undefined): MessagePort {\n if (!port) {\n throw new Error('Invariant violation: MessagePort to parent is not available.')\n }\n return port\n}\n\n/** Check if the current code is running inside a Node.js worker thread. */\nconst isWorkerRuntime: AbstractedWorkerAPI['isWorkerRuntime'] = function isWorkerRuntime() {\n return true // isMainThread\n}\n\n/** Post a message from this worker to the master thread via the parent port. */\nconst postMessageToMaster: AbstractedWorkerAPI['postMessageToMaster'] = function postMessageToMaster(data, transferList) {\n assertMessagePort(parentPort).postMessage(data, transferList as TransferListItem[])\n}\n\n/** Subscribe to messages from the master thread on the parent port. */\nconst subscribeToMasterMessages: AbstractedWorkerAPI['subscribeToMasterMessages'] = function subscribeToMasterMessages(onMessage) {\n if (!parentPort) {\n throw new Error('Invariant violation: MessagePort to parent is not available.')\n }\n const messageHandler = (message: any) => {\n onMessage(message)\n }\n const unsubscribe = () => {\n assertMessagePort(parentPort).off('message', messageHandler)\n }\n assertMessagePort(parentPort).on('message', messageHandler)\n return unsubscribe\n}\n\n/** Bound `on` method from the parent port for adding event listeners. */\nconst addEventListener = parentPort?.on.bind(parentPort)\n/** Bound `postMessage` method from the parent port. */\nconst postMessage = parentPort?.postMessage.bind(parentPort)\n/** Bound `off` method from the parent port for removing event listeners. */\nconst removeEventListener = parentPort?.off.bind(parentPort)\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","/* 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\n/**\n * Create an `expose()` function bound to a specific worker API implementation and global scope.\n * @param implementation - The abstracted worker API for communicating with the master thread.\n * @param self - The worker's global scope for subscribing to error events.\n * @returns The `expose()` function that workers call to register their API.\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\n/** A serializer that can convert between a message format and an input type. */\nexport interface Serializer<Msg = JsonSerializable, Input = any> {\n deserialize(message: Msg): Input\n serialize(input: Input): Msg\n}\n\n/** A serializer implementation that receives a fallback (default) serializer for chaining. */\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\n/**\n * Extend a base serializer with an additional serializer implementation, creating a chain.\n * @param extend - The base serializer to extend.\n * @param implementation - The new serializer implementation that wraps the base.\n * @returns A new serializer combining both behaviors.\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\n/** A JSON-compatible value that can be serialized for worker message passing. */\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\n/** Default serializer that handles Error instances and passes other values through. */\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\n/**\n * Register a custom serializer to extend the default serialization behavior for worker messages.\n * @param serializer - The serializer implementation to register.\n */\nexport function registerSerializer(serializer: SerializerImplementation<JsonSerializable>) {\n globalThis.registeredSerializer = extendSerializer(globalThis.registeredSerializer, serializer)\n}\n\n/**\n * Deserialize a message using the registered serializer.\n * @param message - The serialized message to deserialize.\n * @returns The deserialized value.\n */\nexport function deserialize(message: JsonSerializable): any {\n return globalThis.registeredSerializer.deserialize(message)\n}\n\n/**\n * Serialize an input value using the registered serializer.\n * @param input - The value to serialize.\n * @returns The serialized message.\n */\nexport function serialize(input: any): JsonSerializable {\n return globalThis.registeredSerializer.serialize(input)\n}\n","/** Symbol key for accessing a thread's error observable. */\nexport const $errors = Symbol('thread.errors')\n/** Symbol key for accessing a thread's event observable. */\nexport const $events = Symbol('thread.events')\n/** Symbol key for accessing a thread's terminate function. */\nexport const $terminate = Symbol('thread.terminate')\n/** Symbol key for marking an object as a transferable descriptor. */\nexport const $transferable = Symbol('thread.transferable')\n/** Symbol key for accessing the underlying worker instance of a thread. */\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\n/** Descriptor wrapping a value with its associated transferable objects for zero-copy messaging. */\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\n/**\n * Check whether a value is a `TransferDescriptor` created by `Transfer()`.\n * @param thing - The value to check.\n * @returns True if the value is a transfer descriptor.\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"],"mappings":";AAKA,SAAS,cAAc,0BAA0B;AAEjD,SAAS,gBAAgB;;;ACHzB,OAAO,sBAAsB;;;ACkBtB,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;AAAA,IACjE;AAAA,IAEA,UAAU,OAA+B;AACvC,aAAO,eAAe,UAAU,OAAO,kBAAkB;AAAA,IAC3D;AAAA,EACF;AACF;AAWA,IAAM,yBAA6D;AAAA,EACjE,YAAY,SAAiC;AAC3C,WAAO,OAAO,OAAO,IAAI,MAAM,QAAQ,OAAO,GAAG;AAAA,MAC/C,MAAM,QAAQ;AAAA,MACd,OAAO,QAAQ;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EACA,UAAU,OAA+B;AACvC,WAAO;AAAA,MACL,gBAAgB;AAAA,MAChB,SAAS,MAAM;AAAA,MACf,MAAM,MAAM;AAAA,MACZ,OAAO,MAAM;AAAA,IACf;AAAA,EACF;AACF;AAEA,IAAM,oBAAoB,CAAC,UACzB,SAAS,OAAO,UAAU,YAAY,oBAAoB,SAAS,MAAM,mBAAmB;AAGvF,IAAM,oBAAkD;AAAA,EAC7D,YAAY,SAAgC;AAC1C,WAAO,kBAAkB,OAAO,IAAI,uBAAuB,YAAY,OAAO,IAAI;AAAA,EACpF;AAAA,EACA,UAAU,OAA8B;AACtC,WAAO,iBAAiB,QAAS,uBAAuB,UAAU,KAAK,IAAg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AC;AACD,YAAQ,GAAG,sBAAsB,CAAC,UAAU;AAC1C,UAAI,SAAS,OAAQ,MAAc,YAAY,UAAU;AAEvD,mBAAW,MAAM,yBAAyB,KAAY,GAAG,GAAG;AAAA,MAC9D;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAOA;AACT;;;ADnOA,IAAM,aAAa,SAAS,oBAAoB,MAAM,8DAA8D;AAEpH,SAAS,kBAAkB,MAAmD;AAC5E,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,8DAA8D;AAAA,EAChF;AACA,SAAO;AACT;AAGA,IAAM,kBAA0D,SAASC,mBAAkB;AACzF,SAAO;AACT;AAGA,IAAM,sBAAkE,SAASC,qBAAoB,MAAM,cAAc;AACvH,oBAAkB,UAAU,EAAE,YAAY,MAAM,YAAkC;AACpF;AAGA,IAAM,4BAA8E,SAASC,2BAA0B,WAAW;AAChI,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,8DAA8D;AAAA,EAChF;AACA,QAAM,iBAAiB,CAAC,YAAiB;AACvC,cAAU,OAAO;AAAA,EACnB;AACA,QAAM,cAAc,MAAM;AACxB,sBAAkB,UAAU,EAAE,IAAI,WAAW,cAAc;AAAA,EAC7D;AACA,oBAAkB,UAAU,EAAE,GAAG,WAAW,cAAc;AAC1D,SAAO;AACT;AAGA,IAAM,mBAAmB,YAAY,GAAG,KAAK,UAAU;AAEvD,IAAM,cAAc,YAAY,YAAY,KAAK,UAAU;AAE3D,IAAM,sBAAsB,YAAY,IAAI,KAAK,UAAU;AAQ3D,IAAM,SAAS,aAAa;AAAA,EAC1B;AAAA,EAAiB;AAAA,EAAqB;AACxC,GAAG;AAAA,EACD;AAAA,EAAkB;AAAA,EAAa;AACjC,CAAC;","names":["expose","isWorkerRuntime","postMessageToMaster","subscribeToMasterMessages"]}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
type UnsubscribeFn = () => void;
|
|
2
|
+
/** Abstraction layer for the worker runtime API, used by `expose()` to communicate with the master thread. */
|
|
2
3
|
interface AbstractedWorkerAPI {
|
|
3
4
|
isWorkerRuntime(): boolean;
|
|
4
5
|
postMessageToMaster(message: any, transferList?: Transferable[]): void;
|
|
5
6
|
subscribeToMasterMessages(onMessage: (data: any) => void): UnsubscribeFn;
|
|
6
7
|
}
|
|
8
|
+
/** A function that can be exposed from a worker thread. */
|
|
7
9
|
type WorkerFunction = ((...args: any[]) => any) | (() => any);
|
|
10
|
+
/** An object whose values are functions, representing a module exposed from a worker thread. */
|
|
8
11
|
type WorkerModule<Keys extends string> = {
|
|
9
12
|
[key in Keys]: WorkerFunction;
|
|
10
13
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/threads",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.84",
|
|
4
4
|
"description": "Web workers & worker threads as simple as a function call",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"thread",
|
|
@@ -112,16 +112,16 @@
|
|
|
112
112
|
"package-compile-tsup": "tsup --config tsup.browser.config.ts && tsup --config tsup.node.config.ts && tsup --config tsup.neutral.config.ts"
|
|
113
113
|
},
|
|
114
114
|
"dependencies": {
|
|
115
|
-
"@xylabs/assert": "~5.0.
|
|
115
|
+
"@xylabs/assert": "~5.0.84",
|
|
116
116
|
"debug": "~4.4.3",
|
|
117
117
|
"is-observable-2-1-0": "npm:is-observable@2.1.0",
|
|
118
118
|
"observable-fns": "~0.6.1"
|
|
119
119
|
},
|
|
120
120
|
"devDependencies": {
|
|
121
121
|
"@types/debug": "~4.1.12",
|
|
122
|
-
"@xylabs/eslint-config-flat": "~7.4.
|
|
123
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
124
|
-
"@xylabs/tsconfig": "~7.4.
|
|
122
|
+
"@xylabs/eslint-config-flat": "~7.4.13",
|
|
123
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.13",
|
|
124
|
+
"@xylabs/tsconfig": "~7.4.13",
|
|
125
125
|
"eslint": "~9.39.4",
|
|
126
126
|
"tsup": "~8.5.1",
|
|
127
127
|
"typescript": "~5.9.3",
|