node-apparatus
Version:
A mix of common components needed for awesome node experience
46 lines (45 loc) • 2.31 kB
TypeScript
/**
* Manages a pool of stateful worker threads to handle method invocations.
*
* This class is responsible for initializing worker threads, invoking methods on them,
* and managing their lifecycle. It supports both local and remote method invocations.
*
* @class StatefulProxyManager
*/
export declare class StatefulProxyManager {
private readonly workerCount;
private readonly workerFilePath;
private readonly invocationQueueSizePerWorker;
private readonly spinWaitTime;
private workerSequentialQueue;
private readonly workers;
WorkerCount: number;
private selfWorker;
/**
* Creates an instance of StatefulProxyManager.
*
* @param {number} workerCount - The number of worker threads to create, Pass zero to run in main thread.
* @param {string} workerFilePath - The path to the worker script file which has exported instance of StatefulRecipient.
* @param {number} [invocationQueueSizePerWorker=Number.MAX_SAFE_INTEGER] - The maximum number of method invocations to queue per worker.
* @param {number} [spinWaitTime=100] - The time to wait between attempts to acquire the lock in milliseconds.
*/
constructor(workerCount: number, workerFilePath: string, invocationQueueSizePerWorker?: number, spinWaitTime?: number);
/**
* Initializes the worker threads, must be called before invoking any methods.
*/
initialize(): Promise<void>;
/**
* Invokes a method on a worker thread.
*
* @template T - The return type of the method being invoked.
* @param {string} methodName - The name of the method to invoke.
* @param {any[]} methodArguments - The arguments to pass to the method.
* @param {number} [workerIndex=0] - The index of the worker thread to invoke the method on.
* @param {number} [methodInvocationId=Number.NaN] - The unique identifier for the method invocation.
* @returns {Promise<T>} - A promise that resolves with the return value of the method
* or rejects with an error if the method invocation fails.
*/
invokeMethod<T>(methodName: string, methodArguments?: any[], workerIndex?: number, methodInvocationId?: number): Promise<T | undefined>;
private invokeRemoteMethod;
[Symbol.asyncDispose](): Promise<void>;
}