Skip to content

Commit

Permalink
refactor: cleanup worker message channel handling
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
  • Loading branch information
jerome-benoit committed May 7, 2024
1 parent 49b35da commit 446cd6c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/worker/abstract-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,24 +329,25 @@ export abstract class AbstractWorker<
protected messageEventListener(
messageEvent: MessageEvent<MessageValue<Data>>,
): void {
this.checkMessageWorkerId(messageEvent.data)
if (messageEvent.data.statistics != null) {
const { data } = messageEvent
this.checkMessageWorkerId(data)
const { statistics, checkActive, taskFunctionOperation, taskId, kill } =
data
if (statistics != null) {
// Statistics message received
this.statistics = messageEvent.data.statistics
} else if (messageEvent.data.checkActive != null) {
this.statistics = statistics
} else if (checkActive != null) {
// Check active message received
messageEvent.data.checkActive
? this.startCheckActive()
: this.stopCheckActive()
} else if (messageEvent.data.taskFunctionOperation != null) {
checkActive ? this.startCheckActive() : this.stopCheckActive()
} else if (taskFunctionOperation != null) {
// Task function operation message received
this.handleTaskFunctionOperationMessage(messageEvent.data)
} else if (messageEvent.data.taskId != null && messageEvent.data != null) {
this.handleTaskFunctionOperationMessage(data)
} else if (taskId != null && data != null) {
// Task message received
this.run(messageEvent.data)
} else if (messageEvent.data.kill === true) {
this.run(data)
} else if (kill === true) {
// Kill message received
this.handleKillMessage(messageEvent.data)
this.handleKillMessage(data)
}
}

Expand Down

0 comments on commit 446cd6c

Please sign in to comment.