Browse Source

feat: 主次线程入口abstract类

es6
iapyang 2 years ago
parent
commit
9a5d7694ec
  1. 40
      typescript/core/worker/worker.main_thread.ts
  2. 17
      typescript/core/worker/worker.worker_thread.ts

40
typescript/core/worker/worker.main_thread.ts

@ -0,0 +1,40 @@
import { WorkerMainThreadController } from "./controller/worker.main_thread.controller";
import { IWorkerOptions } from "./worker.core";
/**
* 线Worker
*/
export abstract class MainThreadWorker {
/**
* Worker
*/
public name: string;
/**
* 线
*/
public controller: WorkerMainThreadController;
/**
* Worker
*/
protected isTerminated = false;
public constructor(options: IWorkerOptions) {
this.name = options.workerName;
this.controller = new WorkerMainThreadController(options);
this.initActions();
}
protected abstract initActions(): void;
/**
* worker
* action
*/
public terminate(): void {
this.controller.terminate();
// 设置终止标志位
this.isTerminated = true;
}
}

17
typescript/core/worker/worker.worker_thread.ts

@ -0,0 +1,17 @@
import { WorkerThreadController } from "./controller/worker.worker_thread.controller";
/**
* worker线程实例
*/
export abstract class WorkerThreadWorker {
/**
* Worker 线
*/
protected controller: WorkerThreadController;
public constructor() {
this.controller = new WorkerThreadController();
}
protected abstract initActions(): void;
}
Loading…
Cancel
Save