web-csv-toolbox
    Preparing search index...

    Class ReusableWorkerPool

    Common interface for worker pools. Both ReusableWorkerPool and TransientWorkerPool implement this interface.

    This interface defines the contract for worker pool implementations. Users typically use ReusableWorkerPool for persistent worker pools, while the internal default pool uses TransientWorkerPool for automatic cleanup.

    Implements

    Index

    Constructors

    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...
      });
    • 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();
      });