- constructor(workerScript: string, min: number, max: number,) {
- super(workerScript);
- this.pool = DynamicPool.getInstance(min, max, this.workerScript);
+ constructor(workerScript: string, workerOptions?: WorkerOptions) {
+ super(workerScript, workerOptions);
+ this.workerOptions.poolOptions.errorHandler = (
+ this.workerOptions?.poolOptions?.errorHandler ?? WorkerUtils.defaultErrorHandler
+ ).bind(this) as ErrorHandler<Worker>;
+ this.workerOptions.poolOptions.exitHandler = (
+ this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler
+ ).bind(this) as ExitHandler<Worker>;
+ this.workerOptions.poolOptions.messageHandler.bind(this);
+ this.pool = new DynamicThreadPool<WorkerData>(
+ this.workerOptions.poolMinSize,
+ this.workerOptions.poolMaxSize,
+ this.workerScript,
+ this.workerOptions.poolOptions
+ );