Skip to content

Commit

Permalink
Allow execution of any function in comRouting
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Nov 4, 2023
1 parent 44d0227 commit ba078bb
Showing 1 changed file with 7 additions and 33 deletions.
40 changes: 7 additions & 33 deletions packages/wtd-core/src/WorkerTaskWorker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Payload } from './Payload.js';
import { RawPayload } from './RawPayload.js';
import { WorkerTaskCommandRequest, WorkerTaskCommandResponse, WorkerTaskMessageType } from './WorkerTaskMessage.js';
import { WorkerTaskMessageType } from './WorkerTaskMessage.js';

export type WorkerTaskWorker = {

Expand Down Expand Up @@ -51,38 +51,12 @@ export const printDefaultMessage = (funcName: string, message: WorkerTaskMessage
export const comRouting = (workerImpl: WorkerTaskWorker | InterComWorker, message: MessageEvent<unknown>) => {
const wtmt = (message as MessageEvent).data as WorkerTaskMessageType;
if (wtmt) {
const wtw = workerImpl as WorkerTaskWorker;
const icw = workerImpl as InterComWorker;
switch (wtmt.cmd) {
case WorkerTaskCommandRequest.INIT:
wtw.init?.(wtmt);
break;
case WorkerTaskCommandRequest.INTERMEDIATE:
wtw.intermediate?.(wtmt);
break;
case WorkerTaskCommandRequest.EXECUTE:
wtw.execute?.(wtmt);
break;
case WorkerTaskCommandRequest.INTERCOM_INIT:
icw.interComInit?.(wtmt);
break;
case WorkerTaskCommandResponse.INTERCOM_INIT_COMPLETE:
icw.interComInitComplete?.(wtmt);
break;
case WorkerTaskCommandRequest.INTERCOM_INTERMEDIATE:
icw.interComIntermediate?.(wtmt);
break;
case WorkerTaskCommandResponse.INTERCOM_INTERMEDIATE_CONFIRM:
icw.interComIntermediateConfirm?.(wtmt);
break;
case WorkerTaskCommandRequest.INTERCOM_EXECUTE:
icw.interComExecute?.(wtmt);
break;
case WorkerTaskCommandResponse.INTERCOM_EXECUTE_COMPLETE:
icw.interComExecuteComplete?.(wtmt);
break;
default:
break;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const obj = (workerImpl as any);
const funcName = wtmt.cmd;
if (typeof obj[funcName] === 'function') {
console.log(`Executing ${obj}[${funcName}]`);
obj[funcName](wtmt);
}
}
};

0 comments on commit ba078bb

Please sign in to comment.