console.log(`startService - ${id}`);
if (isMainThread) {
let startService = `${__dirname}/service_runner.js`;
- createWorker(id, startService, filename);
+ let worker = createWorker(id, startService, filename);
+ worker.on('message', (message: any) => {
+ if (message.type === 'stop') {
+ console.log(`${id} will shutdown after ${message.delay}ms`);
+ setTimeout(() => wrt.stopService(id), message.delay);
+ }
+ });
}
}
console.log(`Builtin service is ${serviceName}`);
let startService = `${__dirname}/../service/builtins/${serviceName}.js`;
let worker = createWorker(serviceId, startService, '');
- worker.on('stop', () => {
- terminateWorker(serviceId, 0);
+ worker.on('message', (message: any) => {
+ if (message.type === 'stop') {
+ console.log(`${serviceName} built-in service will be stopped`);
+ terminateWorker(serviceId, message.delay);
+ }
});
}
}
}
}
+function requestStopService(delay: number) {
+ if (parentPort) {
+ parentPort.postMessage({type: 'stop', delay: delay});
+ }
+}
+
let app: any = null;
export function start(id: string, filename: string) {
XWalkExtension.initialize();
XWalkExtension.setRuntimeMessageHandler((type, data) => {
if (type === 'tizen://exit') {
- console.log(`${id} will be closed by ${type}`);
- setTimeout(() => wrt.stopService(id), 500);
+ requestStopService(500);
}
});
}
} catch (e) {
console.log(`exception on start: ${e}`);
- setTimeout(() => wrt.stopService(id), 500);
+ requestStopService(500);
}
}