/**
* Constructs a new poolifier worker.
*
- * @param type - The type of async event.
* @param isMain - Whether this is the main worker or not.
* @param mainWorker - Reference to main worker.
* @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked. The first function is the default function.
/**
* Message port used to communicate with the main worker.
*/
- private port!: MessagePort
+ private port?: MessagePort
/**
* Constructs a new poolifier thread worker.
*
taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>,
opts: WorkerOptions = {}
) {
- super(isMainThread, parentPort as MessagePort, taskFunctions)
+ super(isMainThread, parentPort as MessagePort, taskFunctions, opts)
}
/** @inheritDoc */
/** @inheritDoc */
protected sendToMainWorker (message: MessageValue<Response>): void {
- this.port.postMessage({ ...message, workerId: this.id })
+ this.port?.postMessage({ ...message, workerId: this.id })
}
/**
expect(poolBusy).toBe(1)
const numberOfExitEvents = await waitWorkerEvents(pool, 'exit', max - min)
expect(numberOfExitEvents).toBe(max - min)
+ expect(pool.workerNodes.length).toBe(min)
})
it('Verify scale worker up and down is working', async () => {
- expect(pool.workerNodes.length).toBe(min)
for (let i = 0; i < max * 2; i++) {
pool.execute()
}
expect(poolBusy).toBe(1)
const numberOfExitEvents = await waitWorkerEvents(pool, 'exit', max - min)
expect(numberOfExitEvents).toBe(max - min)
+ expect(pool.workerNodes.length).toBe(min)
})
it('Verify scale thread up and down is working', async () => {
- expect(pool.workerNodes.length).toBe(min)
for (let i = 0; i < max * 2; i++) {
pool.execute()
}