Setu-TS
    Preparing search index...

    Interface IWorkerPool

    A pool of worker threads executing task modules off the event loop.

    A task module is an ES module owned by the application that registers its handler via defineWorkerTask (from @setu-ts/runtime/worker). Tasks are addressed by module specifier — never by closure, because functions cannot cross a thread boundary. Inputs and outputs travel by structured clone.

    const pool = ctx.services.get<IWorkerPool>(CAPABILITIES.WORKER_POOL);
    const thumb = await pool.run<Uint8Array, Uint8Array>(
    new URL('./tasks/resize-image.ts', import.meta.url).href,
    imageBytes,
    );

    0.1.0

    interface IWorkerPool {
        run<TInput, TOutput>(
            taskModule: string,
            input: TInput,
            options?: WorkerRunOptions,
        ): Promise<TOutput>;
        shutdown(): Promise<void>;
        stats(): readonly TaskPoolStats[];
    }

    Implemented by

    Index
    • Runs a task on a pool worker for the given task module, creating the pool lazily on first use.

      Type Parameters

      • TInput
      • TOutput

      Parameters

      • taskModule: string

        Module specifier of a task module that calls defineWorkerTask

      • input: TInput

        Structured-clonable task input

      • Optionaloptions: WorkerRunOptions

        Per-call options

      Returns Promise<TOutput>

      The task's structured-clonable output

      WorkerPoolUnavailableError when the runtime has no worker support (e.g. Cloudflare Workers)

      WorkerTaskError when the task handler throws or the worker crashes

      WorkerTaskTimeoutError when the task exceeds its timeout

      WorkerQueueFullError when the pool's pending queue is at its bound

    • Terminates every worker in every pool and rejects pending tasks. Called by the plugin's onClose hook; safe to call more than once.

      Returns Promise<void>