Crypto Lib
    Preparing search index...

    Class WorkerPool

    A thread pool for offloading CPU-intensive cryptographic tasks to worker threads.

    const pool = new WorkerPool({ size: 4 });
    const result = await pool.execute({
    modulePath: "@noble/hashes/sha256",
    functionName: "sha256",
    args: [new Uint8Array([1, 2, 3])],
    });
    await pool.shutdown();
    Index
    size: number

    Number of worker threads in the pool.

    • Execute a task on an available worker thread.

      The task specifies a module path and function name. The worker will dynamically import the module, call the function with the provided arguments, and return the result.

      Type Parameters

      • T = unknown

      Parameters

      • task: WorkerTask

        Task descriptor with module, function, and arguments.

      Returns Promise<T>

      Promise resolving to the function's return value.