/** @inheritdoc */
public closeChannel (): void {
if (this.info.messageChannel != null) {
+ this.info.messageChannel?.port1.unref()
+ this.info.messageChannel?.port2.unref()
this.info.messageChannel?.port1.close()
this.info.messageChannel?.port2.close()
delete this.info.messageChannel
this.run(message)
} else if (message.kill === true) {
// Kill message received
- !this.isMain && this.stopCheckActive()
- this.emitDestroy()
+ this.handleKillMessage(message)
}
}
}
+ /**
+ * Handles a kill message sent by the main worker.
+ *
+ * @param message - The kill message.
+ */
+ protected handleKillMessage (message: MessageValue<Data>): void {
+ !this.isMain && this.stopCheckActive()
+ this.emitDestroy()
+ }
+
/**
* Starts the worker check active interval.
*/
this.activeInterval = setInterval(
this.checkActive.bind(this),
(this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME) / 2
- ).unref()
+ )
+ this.activeInterval.unref()
}
/**
}
}
+ /** @inheritDoc */
+ protected handleKillMessage (message: MessageValue<Data, unknown>): void {
+ super.handleKillMessage(message)
+ this.port?.unref()
+ this.port?.close()
+ }
+
/** @inheritDoc */
protected get id (): number {
return threadId