+
+ this.mainWorker?.on('message', (value: MessageValue<Data, MainWorker>) => {
+ if (value?.data && value.id) {
+ // Here you will receive messages
+ if (this.async) {
+ this.runInAsyncScope(this.runAsync.bind(this), this, fn, value)
+ } else {
+ this.runInAsyncScope(this.run.bind(this), this, fn, value)
+ }
+ } else if (value.parent) {
+ // Save a reference of the main worker to communicate with it
+ // This will be received once
+ this.mainWorker = value.parent
+ } else if (value.kill) {
+ // Here is time to kill this worker, just clearing the interval
+ if (this.interval) clearInterval(this.interval)
+ this.emitDestroy()
+ }
+ })