}
function createWorker(id: string, startService: string, filename: string) {
- if (workers[id]) {
- console.log(`This worker is already running. ${id}`);
- return;
- }
- workers[id] = new Worker(startService, {
+ return workers[id] ?? (workers[id] = new Worker(startService, {
workerData: {
id,
filename
}
- });
+ }));
}
function terminateWorker(id: string, delay: number) {
if (isMainThread) {
console.log(`Builtin service is ${serviceName}`);
let startService = `${__dirname}/../service/builtins/${serviceName}.js`;
- createWorker(serviceId, startService, '');
+ let worker = createWorker(serviceId, startService, '');
+ worker.on('stop', () => {
+ terminateWorker(serviceId, 0);
+ });
}
}
}
\ No newline at end of file
import '../../common/init';
-import { isMainThread, workerData } from 'worker_threads';
+import { isMainThread, parentPort, workerData } from 'worker_threads';
import { wrt } from '../../browser/wrt';
import * as fs from 'fs';
let tv = wrt.tv as NativeWRTjs.TVExtension;
tv.setWasmFlags();
tv.setDiskCache(app_id);
- tv.delayShutdown();
let files = tv.getWasmFiles(app_id);
console.log(files);
files.forEach((file_path: string) => {
+ tv.delayShutdown();
compileWasmForCaching(file_path);
});
+ if (parentPort) {
+ parentPort.postMessage('stop');
+ }
}
if (!isMainThread) {