### Fixed
- Ensure pool statuses are checked at initialization, `start()` or `destroy()`.
+- Ensure pool `ready` event can be emitted after several `start()/destroy()` cycles.
## [3.0.5] - 2023-10-27
### Fixed
-- Ensure pool ready event can be emitted only once.
+- Ensure pool `ready` event can be emitted only once.
## [3.0.4] - 2023-10-20
### Fixed
-- Fix race condition between ready and task functions worker message handling at startup.
+- Fix race condition between readiness and task functions worker message handling at startup.
- Fix duplicate task function worker usage statistics computation per task function.
- Update task function worker usage statistics if and only if there's at least two different task functions.
- Fix race condition at task function worker usage executing task computation leading to negative value.
max,
median,
min,
- once,
round
} from '../utils'
import { KillBehaviors } from '../worker/worker-options'
* Whether the pool is destroying or not.
*/
private destroying: boolean
+ /**
+ * Whether the pool ready event has been emitted or not.
+ */
+ private readyEventEmitted: boolean
/**
* The start timestamp of the pool.
*/
this.started = false
this.starting = false
this.destroying = false
+ this.readyEventEmitted = false
if (this.opts.startWorkers === true) {
this.start()
}
)
this.emitter?.emit(PoolEvents.destroy, this.info)
this.emitter?.emitDestroy()
+ this.readyEventEmitted = false
this.destroying = false
this.started = false
}
)
workerInfo.ready = message.ready as boolean
workerInfo.taskFunctionNames = message.taskFunctionNames
- if (this.ready) {
- const emitPoolReadyEventOnce = once(
- () => this.emitter?.emit(PoolEvents.ready, this.info),
- this
- )
- emitPoolReadyEventOnce()
+ if (!this.readyEventEmitted && this.ready) {
+ this.readyEventEmitted = true
+ this.emitter?.emit(PoolEvents.ready, this.info)
}
}
)
expect(pool.info.started).toBe(false)
expect(pool.info.ready).toBe(false)
+ expect(pool.readyEventEmitted).toBe(false)
expect(pool.workerNodes).toStrictEqual([])
await expect(pool.execute()).rejects.toThrow(
new Error('Cannot execute a task on not started pool')
pool.start()
expect(pool.info.started).toBe(true)
expect(pool.info.ready).toBe(true)
+ await waitPoolEvents(pool, PoolEvents.ready, 1)
+ expect(pool.readyEventEmitted).toBe(true)
expect(pool.workerNodes.length).toBe(numberOfWorkers)
for (const workerNode of pool.workerNodes) {
expect(workerNode).toBeInstanceOf(WorkerNode)
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(pool.started).toBe(false)
+ expect(pool.readyEventEmitted).toBe(false)
expect(pool.workerNodes.length).toBe(0)
expect(numberOfExitEvents).toBe(min)
expect(poolDestroy).toBe(1)
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(pool.started).toBe(false)
+ expect(pool.readyEventEmitted).toBe(false)
expect(pool.workerNodes.length).toBe(0)
expect(numberOfExitEvents).toBe(numberOfWorkers)
expect(poolDestroy).toBe(1)
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(pool.started).toBe(false)
+ expect(pool.readyEventEmitted).toBe(false)
expect(pool.workerNodes.length).toBe(0)
expect(numberOfExitEvents).toBe(min)
expect(poolDestroy).toBe(1)
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(pool.started).toBe(false)
+ expect(pool.readyEventEmitted).toBe(false)
expect(pool.workerNodes.length).toBe(0)
expect(numberOfExitEvents).toBe(numberOfThreads)
expect(poolDestroy).toBe(1)
max,
median,
min,
- once,
+ // once,
round,
secureRandom,
sleep
expect(max(1, 1)).toBe(1)
})
- it('Verify once()', () => {
- let called = 0
- const fn = () => ++called
- const onceFn = once(fn, this)
- const result1 = onceFn()
- expect(called).toBe(1)
- expect(result1).toBe(1)
- const result2 = onceFn()
- expect(called).toBe(1)
- expect(result2).toBe(1)
- const result3 = onceFn()
- expect(called).toBe(1)
- expect(result3).toBe(1)
- })
+ // it('Verify once()', () => {
+ // let called = 0
+ // const fn = () => ++called
+ // const onceFn = once(fn, this)
+ // const result1 = onceFn()
+ // expect(called).toBe(1)
+ // expect(result1).toBe(1)
+ // const result2 = onceFn()
+ // expect(called).toBe(1)
+ // expect(result2).toBe(1)
+ // const result3 = onceFn()
+ // expect(called).toBe(1)
+ // expect(result3).toBe(1)
+ // })
})