The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [2.0.2] - 2021-dd-05
+
+### Bug fixes
+
+- Fix `busy` event emission on fixed pool type
+
## [2.0.1] - 2021-16-03
### Bug fixes
this,
() => {
const workerCreated = this.createAndSetupWorker()
- this.registerWorkerMessageListener(workerCreated, message => {
+ this.registerWorkerMessageListener(workerCreated, async message => {
const tasksInProgress = this.tasks.get(workerCreated)
if (
isKillBehavior(KillBehaviors.HARD, message.kill) ||
tasksInProgress === 0
) {
// Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime)
- void this.destroyWorker(workerCreated)
+ await this.destroyWorker(workerCreated)
}
})
return workerCreated
public execute (data: Data): Promise<Response> {
// Configure worker to handle message with the specified task
const worker = this.chooseWorker()
- this.increaseWorkersTask(worker)
- this.checkAndEmitBusy()
const messageId = ++this.nextMessageId
const res = this.internalExecute(worker, messageId)
+ this.checkAndEmitBusy()
this.sendToWorker(worker, { data: data || ({} as Data), id: messageId })
return res
}
worker: Worker,
messageId: number
): Promise<Response> {
+ this.increaseWorkersTask(worker)
return new Promise<Response>((resolve, reject) => {
this.promiseMap.set(messageId, { resolve, reject, worker })
})
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.push(pool.execute({ test: 'test' }))
}
- expect(poolBusy).toBe(numberOfWorkers)
+ // The `busy` event is triggered when the number of submitted tasks at once reach the number of fixed pool workers.
+ // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool.
+ expect(poolBusy).toBe(numberOfWorkers + 1)
pool.destroy()
})
})
}
expect(pool.workers.length).toBeLessThanOrEqual(max)
expect(pool.workers.length).toBeGreaterThan(min)
+ // The `busy` event is triggered when the number of submitted tasks at once reach the max number of workers in the dynamic pool.
+ // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool.
expect(poolBusy).toBe(max + 1)
const numberOfExitEvents = await TestUtils.waitExits(pool, max - min)
expect(numberOfExitEvents).toBe(max - min)
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.push(pool.execute({ test: 'test' }))
}
- expect(poolBusy).toBe(numberOfWorkers)
+ // The `busy` event is triggered when the number of submitted tasks at once reach the number of fixed pool workers.
+ // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool.
+ expect(poolBusy).toBe(numberOfWorkers + 1)
})
it('Verify that is possible to have a worker that return undefined', async () => {
promises.push(pool.execute({ test: 'test' }))
}
expect(pool.workers.length).toBe(max)
+ // The `busy` event is triggered when the number of submitted tasks at once reach the max number of workers in the dynamic pool.
+ // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool.
expect(poolBusy).toBe(max + 1)
const res = await TestUtils.waitExits(pool, max - min)
expect(res).toBe(max - min)
for (let i = 0; i < numberOfThreads * 2; i++) {
promises.push(pool.execute({ test: 'test' }))
}
- expect(poolBusy).toBe(numberOfThreads)
+ // The `busy` event is triggered when the number of submitted tasks at once reach the number of fixed pool workers.
+ // So in total numberOfThreads + 1 times for a loop submitting up to numberOfThreads * 2 tasks to the fixed pool.
+ expect(poolBusy).toBe(numberOfThreads + 1)
})
it('Verify that is possible to have a worker that return undefined', async () => {