Browse Source

KERNEL-12095 worker主进程在helper层创建

es6
Austin.Duan 2 years ago
parent
commit
ed92dda2a5
  1. 1
      bin/cli/worker/cli.worker.js
  2. 26
      bin/cli/worker/template/main_thread/main_thread.helper.t
  3. 14
      bin/cli/worker/template/main_thread/main_thread.t

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

@ -45,6 +45,7 @@ module.exports = {
'action.worker_ability_test.ts': path.resolve(__dirname, './template/main_thread/action/action.worker_ability_test.t'),
},
[`${name}_main_thread.ts`]: path.resolve(__dirname, './template/main_thread/main_thread.t'),
[`${name}_main_thread.helper.ts`]: path.resolve(__dirname, './template/main_thread/main_thread.helper.t'),
},
utils: {
'action_type.ts': path.resolve(__dirname, './template/utils/action_type.t'),

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

@ -0,0 +1,26 @@
import { ${WorkerName}MainThreadWorker } from './new_main_thread';
// 不需要一起打包的话则不需要引入这行
import { workerUrl } from 'fui-worker!../worker_thread/new_worker_thread';
// MainThread的创建在helper层处理
export class ${WorkerName}MainThreadWorkerHelper {
public createMainTreadWorker() {
return BI.Workers.createWorker(${WorkerName}MainThreadWorker, {
workerUrl: this.urlFormatter(workerUrl),
workerName: BI.UUID(),
});
}
private urlFormatter(v: string) {
return v;
}
}
export const mainThreadWorkerHelper = new ${WorkerName}MainThreadWorkerHelper();
// 调用示例
mainThreadWorkerHelper.createMainTreadWorker()
.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