Class WorkerManager<Manifest>

Type Parameters

Hierarchy

  • WorkerManager

Constructors

  • Constructs a new instance of the class using the provided parameters.

    Type Parameters

    Parameters

    • config: {
          cores: number;
          logger: Logger;
          manifest: Manifest;
          workerFactory: WorkerFactory;
      }

      The configuration for the constructor.

      • cores: number

        The number of cores to allocate for the worker pool.

      • logger: Logger

        The logger instance for logging messages.

      • manifest: Manifest

        The manifest containing method definitions.

      • workerFactory: WorkerFactory

        The factory for creating worker instances.

    Returns WorkerManager<Manifest>

Properties

logger: Logger
methods: Manifest

Methods exposes a fully typed interface for making calls using workers. It provides all the available methods provided by the manifest with proper types applied.

pool: WorkerPool

Methods

  • Returns a promise that resolves when the pool status becomes 'idle', or rejects if the pool status changes to 'terminated' or an error occurs.

    Returns Promise<void>

    A promise that resolves when the pool is idle or rejects with an error.

  • Destroys the WorkerManager instance and terminates its associated pool.

    Parameters

    • Optional params: {
          force?: boolean;
      } = {}

      An optional configuration object.

      • Optional force?: boolean

        Indicates whether to forcefully terminate the pool.

    Returns Promise<void>

    A promise that resolves when the destruction process is complete.

  • Enqueues a task to be processed by the worker pool.

    Parameters

    Returns Promise<WorkerResult>

    A promise that resolves with the result of the task or rejects with an error if the task fails or cannot be processed.

  • Returns a promise that resolves when the pool status becomes 'idle', or rejects if the pool status becomes 'terminated'.

    Returns Promise<void>

    A promise that resolves once the pool status is 'idle', or rejects if the pool status becomes 'terminated'.

  • Creates and initializes a new instance of WorkerManager.

    Type Parameters

    Parameters

    • options: {
          cores?: number;
          logger?: Logger;
          manifest: Manifest;
          workerFactory: WorkerFactory;
      }

      The configuration options for the WorkerManager.

      • Optional cores?: number

        The number of cores to allocate for workers. Defaults to 1.

      • Optional logger?: Logger
      • manifest: Manifest

        The manifest defining the worker capabilities and operations.

      • workerFactory: WorkerFactory

        The factory for creating workers.

    Returns Promise<WorkerManager<Manifest>>

    A promise that resolves to a new WorkerManager instance.

Generated using TypeDoc