fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

62 lines
1.6 KiB

import { ${WorkerName}MainThreadWorker } from './main_thread/${workerName}_main_thread';
// 不需要一起打包的话则不需要引入这行
import { workerUrl } from 'fui-worker!./worker_thread/${workerName}_worker_thread';
export class ${WorkerName}WorkerHelper {
public workers = new Map<string, ${WorkerName}MainThreadWorker>();
/**
* worker
* @param key worker key
*/
public createMainThreadWorker(key: string = '') {
if (this.workers.has(key)) {
return this.workers.get(key);
}
const newWorker = BI.Workers.createWorker(${WorkerName}MainThreadWorker, {
workerUrl: this.urlFormatter(workerUrl),
workerName: BI.UUID(),
});
this.workers.set(key, newWorker);
return newWorker;
}
/**
* worker url
* @param url worker url
*/
private urlFormatter(url: string) {
return url;
}
/**
* workerkey
* @param key key
*/
public terminate(key?: string) {
if (BI.isNull(key)) {
this.workers.forEach(thread => {
thread.terminate();
});
this.workers.clear();
return;
}
this.workers.get(key)?.terminate();
this.workers.delete(key);
}
}
export const ${workerName}WorkerHelper = new ${WorkerName}WorkerHelper();
// 使用示例
const worker = ${workerName}WorkerHelper.createMainThreadWorker();
worker.testCommunication()
.then(res => console.log(res));