- protected newWorker (): WorkerWithMessageChannel {
- const worker: WorkerWithMessageChannel = new Worker(this.filePath, {
- env: SHARE_ENV
- })
- worker.on('error', this.opts.errorHandler ?? (() => {}))
- worker.on('online', this.opts.onlineHandler ?? (() => {}))
- // TODO handle properly when a thread exit
- worker.on('exit', this.opts.exitHandler ?? (() => {}))
- this.workers.push(worker)
- const { port1, port2 } = new MessageChannel()
- worker.postMessage({ parent: port1 }, [port1])
- worker.port1 = port1
- worker.port2 = port2
- // we will attach a listener for every task,
- // when task is completed the listener will be removed but to avoid warnings we are increasing the max listeners size
- worker.port2.setMaxListeners(this.opts.maxTasks ?? 1000)
- // init tasks map
- this.tasks.set(worker, 0)
- return worker
+ /** @inheritDoc */
+ protected get worker (): WorkerType {
+ return WorkerTypes.thread
+ }
+
+ /** @inheritDoc */
+ protected get minSize (): number {
+ return this.numberOfWorkers
+ }
+
+ /** @inheritDoc */
+ protected get maxSize (): number {
+ return this.numberOfWorkers
+ }
+
+ /** @inheritDoc */
+ protected get busy (): boolean {
+ return this.internalBusy()