web-csv-toolbox - v0.14.0
    Preparing search index...

    Class ReusableWorkerPool

    Re-export the ReusableWorkerPool class with Web-specific createWorker.

    This wrapper ensures the Web version of createWorker is used. All implementation details are in ReusableWorkerPool.shared.ts.

    Hierarchy

    • ReusableWorkerPool
      • ReusableWorkerPool
    Index

    Constructors

    Properties

    createWorker: CreateWorkerFn

    Accessors

    Methods

    • Dispose of the worker pool, terminating all workers.

      This method is called automatically when using the using syntax. For manual cleanup, use terminate instead.

      Returns void

      using pool = new ReusableWorkerPool({ maxWorkers: 4 });
      // Workers are automatically terminated when leaving scope
      const pool = new ReusableWorkerPool({ maxWorkers: 4 });
      try {
      // Use pool
      } finally {
      pool.terminate(); // Preferred over pool[Symbol.dispose]()
      }
    • Check if the pool has reached its maximum capacity.

      Returns boolean

      True if the pool is at maximum capacity, false otherwise

      This method is useful for implementing early rejection of requests when the worker pool is saturated, preventing resource exhaustion.

      import { Hono } from 'hono';
      import { ReusableWorkerPool } from 'web-csv-toolbox';

      const pool = new ReusableWorkerPool({ maxWorkers: 4 });

      app.post('/validate-csv', async (c) => {
      // Early rejection if pool is saturated
      if (pool.isFull()) {
      return c.json({ error: 'Service busy, please try again later' }, 503);
      }

      // Process CSV...
      });
    • Internal

      Release a worker back to the pool. For ReusableWorkerPool, this does nothing as workers are kept alive and reused.

      Parameters

      • _worker: Worker

        The worker to release

      Returns void

    • Terminate all workers in the pool and clean up resources.

      This method should be called when the pool is no longer needed, typically during application shutdown.

      Returns void

      const pool = new ReusableWorkerPool({ maxWorkers: 4 });

      // When shutting down
      pool.terminate();
      import { Hono } from 'hono';
      import { ReusableWorkerPool } from 'web-csv-toolbox';

      const app = new Hono();
      const pool = new ReusableWorkerPool({ maxWorkers: 4 });

      app.onShutdown(() => {
      pool.terminate();
      });