forked from fanruan/fineui
iapyang
2 years ago
2 changed files with 57 additions and 0 deletions
@ -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; |
||||
} |
||||
} |
@ -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…
Reference in new issue