Skip to content

Commit b447fde

Browse files
committed
some small unix signal handler clarification
1 parent 1f118e6 commit b447fde

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

backend/src/services/unix-signal-service.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,25 @@ export class UnixSignalService implements IUnixSignalService {
5252

5353
/**
5454
* Registers the given handler to execute for the given signal.
55-
* @param signal The signal to register
55+
* @param signal The signal to register, for example SIGINT
5656
* @param handler The handler to use for the signal
5757
*/
5858
public async registerSignalHandler(
5959
signal: NodeJS.Signals,
6060
handler: ISignalHandler,
6161
): Promise<void> {
6262
if (!this._handlers.has(signal)) {
63-
this._handlers.set(signal, [() => {
64-
// TODO I don't know why
65-
console.error("process.exit", signal, handler)
63+
// Ensure an erray with the default handler exists, to which more
64+
// handlers can be added
65+
const defaultHandler = () => {
66+
console.error(`Received signal ${signal}, exiting`)
6667
process.exit()
67-
}]);
68+
}
69+
70+
this._handlers.set(signal, [defaultHandler]);
6871

72+
// Ensure all added handlers in the array are called, when the signal event
73+
// happens
6974
process.on(signal, () => this.handleSignal(signal));
7075
}
7176

0 commit comments

Comments
 (0)