Browse Source

refactor: 调整下数据结构

es6
iapyang 2 years ago
parent
commit
2548a525dd
  1. 4
      typescript/core/worker/action/worker.action.ts
  2. 9
      typescript/core/worker/worker.main_thread.ts
  3. 11
      typescript/core/worker/worker.worker_thread.ts
  4. 6
      typescript/core/worker/workers.ts

4
typescript/core/worker/action/worker.action.ts

@ -3,7 +3,7 @@ import type { WorkerBaseController } from "../controller/worker.controller";
/**
*
*/
export default abstract class WorkerBaseAction {
export class WorkerBaseAction {
/**
*
*/
@ -24,5 +24,5 @@ export default abstract class WorkerBaseAction {
/**
*
*/
protected abstract addActionHandler(): void;
protected addActionHandler() {}
}

9
typescript/core/worker/worker.main_thread.ts

@ -1,3 +1,4 @@
import type { WorkerBaseAction } from "./action/worker.action";
import { WorkerMainThreadController } from "./controller/worker.main_thread.controller";
import { IWorkerOptions } from "./worker.core";
@ -37,4 +38,12 @@ export abstract class MainThreadWorker {
// 设置终止标志位
this.isTerminated = true;
}
/**
* action
* @param Action action类
*/
protected createAction<T extends typeof WorkerBaseAction>(Action: T): InstanceType<T> {
return (new Action(this.controller, this)) as InstanceType<T>;
}
}

11
typescript/core/worker/worker.worker_thread.ts

@ -1,3 +1,4 @@
import type { WorkerBaseAction } from "./action/worker.action";
import { WorkerThreadController } from "./controller/worker.worker_thread.controller";
/**
@ -11,7 +12,17 @@ export abstract class WorkerThreadWorker {
public constructor() {
this.controller = new WorkerThreadController();
this.initActions();
}
protected abstract initActions(): void;
/**
* action
* @param Action action类
*/
protected createAction<T extends typeof WorkerBaseAction>(Action: T): InstanceType<T> {
return (new Action(this.controller, this)) as InstanceType<T>;
}
}

6
typescript/core/worker/workers.ts

@ -3,7 +3,9 @@ import { WorkerBaseController } from "./controller/worker.controller";
import { WorkerMessageType } from "./worker.core";
import { WorkerMainThreadController } from "./controller/worker.main_thread.controller";
import { WorkerThreadController } from "./controller/worker.worker_thread.controller";
import WorkerBaseAction from "./action/worker.action";
import { WorkerBaseAction } from "./action/worker.action";
import { MainThreadWorker } from "./worker.main_thread";
import { WorkerThreadWorker } from "./worker.worker_thread";
export const Workers = {
WorkerChannel,
@ -11,5 +13,7 @@ export const Workers = {
WorkerMainThreadController,
WorkerThreadController,
WorkerBaseAction,
MainThreadWorker,
WorkerThreadWorker,
WorkerMessageType,
};

Loading…
Cancel
Save