Browse Source

Merge pull request #119950 in DEC/fineui from master to feature/x

* commit '1f439081e8ebb50f39a476cbe368de222143fac8':
  加下注释
  KERNEL-12095 改下模板
  更新下模板
  KERNEL-12095 WorkerHelper改下设计,支持校验、创建、终止worker
  KERNEL-12095 worker主进程在helper层创建
es6
superman 2 years ago
parent
commit
4f0dcba4fe
  1. 1
      bin/cli/worker/cli.worker.js
  2. 45
      bin/cli/worker/template/main_thread.helper.t
  3. 14
      bin/cli/worker/template/main_thread/main_thread.t

1
bin/cli/worker/cli.worker.js

@ -56,6 +56,7 @@ module.exports = {
},
[`${name}_worker_thread.ts`]: path.resolve(__dirname, './template/worker_thread/worker_thread.t'),
},
[`${name}_main_thread.helper.ts`]: path.resolve(__dirname, './template/main_thread.helper.t'),
},
};

45
bin/cli/worker/template/main_thread.helper.t

@ -0,0 +1,45 @@
import { ${WorkerName}MainThreadWorker } from './main_thread/${workerName}_main_thread';
// 不需要一起打包的话则不需要引入这行
import { workerUrl } from 'fui-worker!./worker_thread/${workerName}_worker_thread';
export class ${WorkerName}WorkerHelper {
private worker: ${WorkerName}MainThreadWorker;
/**
* 拿到helper中的worker
*/
public getWorker() {
if (this.worker) {
return this.worker;
}
this.worker = BI.Workers.createWorker(${WorkerName}MainThreadWorker, {
workerUrl: this.urlFormatter(workerUrl),
workerName: BI.UUID(),
});
return this.worker;
}
/**
* 格式化worker url比如补充一些环境信息到参数里
* @param url worker url
*/
private urlFormatter(url: string) {
return url;
}
/**
* 终止worker
*/
public terminate() {
this.worker?.terminate();
}
}
// 使用示例
// const workerHelper = new ${WorkerName}WorkerHelper();
// workerHelper.getWorker()
// .testCommunication()
// .then(res => console.log(res));

14
bin/cli/worker/template/main_thread/main_thread.t

@ -1,8 +1,6 @@
import { WorkerAbilityTestMainThreadAction } from './action/action.worker_ability_test';
// 不需要一起打包的话则不需要引入这行
import { workerUrl } from 'fui-worker!../worker_thread/${workerName}_worker_thread';
class ${WorkerName}MainTreadWorker extends BI.Workers.MainThreadWorker {
export class ${WorkerName}MainThreadWorker extends BI.Workers.MainThreadWorker {
private communicationTest: WorkerAbilityTestMainThreadAction;
public initActions(): void {
@ -13,13 +11,3 @@ class ${WorkerName}MainTreadWorker extends BI.Workers.MainThreadWorker {
return this.communicationTest.communicationTest();
}
}
const ${workerName}MainTreadWorker = BI.Workers.createWorker(${WorkerName}MainTreadWorker, {
workerUrl,
workerName: BI.UUID(),
});
${workerName}MainTreadWorker.testCommunication()
.then(v => {
console.log(v);
});

Loading…
Cancel
Save