Create a new ReusableWorkerPool.
Configuration options for the pool
Get the current number of workers in the pool.
The number of active workers
Dispose of the worker pool, terminating all workers.
This method is called automatically when using the using syntax.
For manual cleanup, use terminate instead.
InternalGet the next request ID for this pool.
The next request ID
Check if the pool has reached its maximum capacity.
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...
});
InternalRelease a worker back to the pool. For ReusableWorkerPool, this does nothing as workers are kept alive and reused.
The worker to release
Common interface for worker pools. Both ReusableWorkerPool and TransientWorkerPool implement this interface.
Remarks
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.