/// import { MessagePort, Worker } from "worker_threads"; import { DefaultListener, ListenerSignature, TypedEmitter } from "tiny-typed-emitter"; import type { threadModule, ThreadOptions, ThreadExports, ThreadData, PromisefulModule, ThreadExitInfo } from "./Types"; import { ParentThread } from "./Parent"; export declare class Thread = DefaultListener> extends TypedEmitter { private _threadStore; worker?: MessagePort | Worker; data?: D; threadModule?: string; protected _sharedArrayBuffer: SharedArrayBuffer; private _promises; private _promiseKey; private _functionQueue; private _stopExecution; importedThreads: Record>; private _internalFunctions?; static spawnedThreads: Record>; exited: Promise; private _exited; private _exitResolve; get running(): boolean; private proxyPorts; /** * Returns a promise containing a constructed `Thread`. * @param {MessagePort} worker Port the thread will communicate on * @param {Object} options Data passed to thread on start * @param {SharedArrayBuffer} options.sharedArrayBuffer Shared memory containing thread parameters */ constructor(worker: Worker | MessagePort | false, options: ThreadOptions); loadExports: (exports: ThreadExports) => void; queue: M; static addThread: (threadName: string, thread: Thread) => void; static newProxyThread: (threadName: string, exports: E_1) => ParentThread; terminate: () => Promise; emit: (eventName: U, ...args: Parameters) => boolean; /** * Stops execution of the function queue. */ stopExecution: () => Promise; /** * Imports a reference to a running thread by its threadName, * @example // To load a reference to the thread running file `./somepath/helloWorld` * const helloWorldThread = thisThread.require('helloWorld') * thisThread.threads['helloWorld'] // Also set to the thread reference for non async access */ require: = DefaultListener>(threadName: string, options?: { isPath?: true | undefined; } | undefined) => Promise & Omit, "require">>; /** * Creates a new `workerPort` for xThread communication, handled by `_messageHandler`. * Returns the new `workerPort` and this threads `workerData`. * @returns {{MessagePort: MessagePort, workerData:{sharedArrayBuffer:SharedArrayBuffer} Transfers: [MessagePort]}} Object containing data needed to reference this thread. */ _getThreadReferenceData: (threadName: string) => Promise; buildReferenceData: () => Promise; get working(): number; set working(value: number); get queued(): number; set queued(value: number); /** * Queues a function to be executed in the future. * @param {Object} message Object containing function info. * @param {string} message.func Function from `this._functions` to execute. * @param {*} message.data Data passed to `function`. * @param {string|number} message.promiseKey Unique key used for returned promise. */ private _queueSelfFunction; /** * Runs thread queue. * @returns {Promise} functions run. */ private _runQueue; /** * Handler function for thread communication. * @param {Object} message * @param {string} message.type */ private _messageHandler; /** * Returns a function for handling xThread funciton calls. * @param workerPort the port calls are handled over. * @returns xThread function handler. */ private _functionHandler; /** * Calls a thread function. * @param {string} func Key of `function` to execute. * @param {*} data Data to give to the `function`. * @param {number|string} promiseKey Unique key used for returned promise. * * @returns {Promise} Promise that resolves with function result. */ private _callThreadFunction; } //# sourceMappingURL=Thread.d.ts.map