- protected afterWorkerSetup (worker: ThreadWorkerWithMessageChannel): void {
- 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 the 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)
- this.registerWorkerMessageListener(worker, super.workerListener())