Class WorkerManager<W>

Type Parameters

  • W extends ModuleMethods

Hierarchy

  • WorkerManager

Implements

  • WorkerManagerInterface<W>

Constructors

  • Type Parameters

    • W extends ModuleMethods

    Parameters

    • __namedParameters: {
          cores?: number;
          logger: Logger;
          workerFactory: (() => Promise<ModuleThread<W>>);
      }
      • Optional cores?: number
      • logger: Logger
      • workerFactory: (() => Promise<ModuleThread<W>>)
          • (): Promise<ModuleThread<W>>
          • Returns Promise<ModuleThread<W>>

    Returns WorkerManager<W>

Properties

logger: Logger
pool: Pool<ModuleThread<W>>

Methods

  • Type Parameters

    • T

    Parameters

    • f: ((worker) => Promise<T>)
        • (worker): Promise<T>
        • Parameters

          • worker: ModuleThread<W>

          Returns Promise<T>

    Returns Promise<T>

  • Returns Promise<void>

  • Parameters

    • Optional __namedParameters: {
          force?: boolean;
      }
      • Optional force?: boolean

    Returns Promise<void>

  • Type Parameters

    • T

    Parameters

    • f: ((worker) => Promise<T>)
        • (worker): Promise<T>
        • Parameters

          • worker: ModuleThread<W>

          Returns Promise<T>

    Returns QueuedTask<ModuleThread<W>, T>

  • Returns Promise<Error[]>

  • Creates the WorkerManager The workerFactory needs to be a callback: () => spawn(new Worker(workerPath)) The spawn and Worker can be imported from threads The workerPath must point to a worker script The workerPath can be either an absolute path or relative path If it is a relative path, it has to be relative to the file location where the function expression is defined If cores is set to 0, this creates a useless worker pool Use undefined to mean using all cores

    Type Parameters

    • W extends ModuleMethods

    Parameters

    • __namedParameters: {
          cores?: number;
          logger?: Logger;
          workerFactory: (() => Promise<ModuleThread<W>>);
      }
      • Optional cores?: number
      • Optional logger?: Logger
      • workerFactory: (() => Promise<ModuleThread<W>>)
          • (): Promise<ModuleThread<W>>
          • Returns Promise<ModuleThread<W>>

    Returns Promise<WorkerManager<W>>

Generated using TypeDoc