const station = new ChargingStation(data.index, data.templateFile);
station.start();
}
-
-process.on('uncaughtException', (err) => {
- throw err;
-});
-
-process.on('unhandledRejection', (reason) => {
- throw reason;
-});
*/
constructor(workerScript: string, workerOptions?: WorkerOptions) {
super(workerScript, workerOptions);
+ this.workerOptions.poolOptions.errorHandler =
+ this.workerOptions?.poolOptions?.errorHandler ?? WorkerUtils.defaultErrorHandler;
this.workerOptions.poolOptions.exitHandler =
this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler;
this.pool = new DynamicThreadPool<WorkerData>(
/* This is intentional */
});
});
- worker.on('error', () => {
- /* This is intentional */
+ worker.on('error', (error) => {
+ WorkerUtils.defaultErrorHandler(error);
});
worker.on('exit', (code) => {
WorkerUtils.defaultExitHandler(code);
*/
constructor(workerScript: string, workerOptions?: WorkerOptions) {
super(workerScript, workerOptions);
+ this.workerOptions.poolOptions.errorHandler =
+ this.workerOptions?.poolOptions?.errorHandler ?? WorkerUtils.defaultErrorHandler;
this.workerOptions.poolOptions.exitHandler =
this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler;
this.pool = new FixedThreadPool(
console.error(chalk.red(`Worker stopped with exit code ${code}`));
}
};
+
+ public static defaultErrorHandler = (error: Error): void => {
+ console.error(chalk.red('Worker errored: ', error));
+ };
}