fix: ctrl+c not working
Massimo Melina committed
Jan 16, 2022 at 11:25 UTC
1cb188c22c25c8723d01364fb4a988f372628294
2 files changed
+7
-5
src/misc.ts
+4
-4
@@ -71,16 +71,16 @@ export function randomId(len = 10) {
71
.replace(/l/g, 'L'); // avoid confusion reading l1
72
}
73
74
-export function onProcessExit(cb: ()=>void) {
74
+export function onProcessExit(cb: (signal:string)=>void) {
75
onFirstEvent(process, ['exit', 'SIGQUIT', 'SIGTERM', 'SIGINT'], cb)
76
}
77
78
-export function onFirstEvent(emitter:EventEmitter, events: string[], cb: ()=> void) {
78
+export function onFirstEvent(emitter:EventEmitter, events: string[], cb: (...args:any[])=> void) {
79
let already = false
80
for (const e of events)
81
- emitter.on(e, () => {
81
+ emitter.on(e, (...args) => {
82
if (already) return
83
already = true
84
- cb()
84
+ cb(...args)
85
})
86
}
src/plugins.ts
+3
-1
@@ -177,7 +177,9 @@ function deleteModule(id: string) {
177
}
178
}
179
180
-onProcessExit(() => {
180
+onProcessExit(sig => {
181
for (const pl of Object.values(plugins))
182
pl.unload()
183
+ if (sig === 'SIGINT') // ctrl+c
184
+ setTimeout(()=> process.exit(0))
185
})