+ protected messageListener (message: MessageValue<Data, MainWorker>): void {
+ if (message.id != null && message.data != null) {
+ // Task message received
+ const fn = this.getTaskFunction(message.name)
+ if (fn?.constructor.name === 'AsyncFunction') {
+ this.runInAsyncScope(this.runAsync.bind(this), this, fn, message)
+ } else {
+ this.runInAsyncScope(this.runSync.bind(this), this, fn, message)
+ }
+ } else if (message.parent != null) {
+ // Main worker reference message received
+ this.mainWorker = message.parent
+ } else if (message.kill != null) {
+ // Kill message received
+ this.aliveInterval != null && clearInterval(this.aliveInterval)
+ this.emitDestroy()
+ } else if (message.statistics != null) {
+ // Statistics message received
+ this.statistics = message.statistics
+ }