Skip to content

Commit

Permalink
fix: ctrl+c not working
Browse files Browse the repository at this point in the history
  • Loading branch information
rejetto committed Jan 16, 2022
1 parent 35758b9 commit 1cb188c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ export function randomId(len = 10) {
.replace(/l/g, 'L'); // avoid confusion reading l1
}

export function onProcessExit(cb: ()=>void) {
export function onProcessExit(cb: (signal:string)=>void) {
onFirstEvent(process, ['exit', 'SIGQUIT', 'SIGTERM', 'SIGINT'], cb)
}

export function onFirstEvent(emitter:EventEmitter, events: string[], cb: ()=> void) {
export function onFirstEvent(emitter:EventEmitter, events: string[], cb: (...args:any[])=> void) {
let already = false
for (const e of events)
emitter.on(e, () => {
emitter.on(e, (...args) => {
if (already) return
already = true
cb()
cb(...args)
})
}
4 changes: 3 additions & 1 deletion src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ function deleteModule(id: string) {
}
}

onProcessExit(() => {
onProcessExit(sig => {
for (const pl of Object.values(plugins))
pl.unload()
if (sig === 'SIGINT') // ctrl+c
setTimeout(()=> process.exit(0))
})

0 comments on commit 1cb188c

Please sign in to comment.