*/
protected handleKillMessage (message: MessageValue<Data>): void {
this.stopCheckActive()
- this.opts.killHandler?.()
- this.emitDestroy()
+ if (isAsyncFunction(this.opts.killHandler)) {
+ (this.opts.killHandler?.() as Promise<void>)
+ .then(() => this.emitDestroy())
+ .catch(EMPTY_FUNCTION)
+ } else {
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
+ this.opts.killHandler?.() as void
+ this.emitDestroy()
+ }
}
/**
expect(worker.opts.killHandler.calledOnce).toBe(true)
})
- // it('Verify that async kill handler is called when worker is killed', () => {
- // const worker = new ClusterWorker(() => {}, {
- // killHandler: sinon.stub().resolves()
- // })
- // worker.isMain = false
- // worker.handleKillMessage()
- // expect(worker.opts.killHandler.calledOnce).toBe(true)
- // })
+ it('Verify that async kill handler is called when worker is killed', () => {
+ const killHandlerStub = sinon.stub().returns()
+ const worker = new ClusterWorker(() => {}, {
+ killHandler: async () => Promise.resolve(killHandlerStub())
+ })
+ worker.isMain = false
+ worker.handleKillMessage()
+ expect(killHandlerStub.calledOnce).toBe(true)
+ })
it('Verify that handleError() method works properly', () => {
const error = new Error('Error as an error')