Skip to content

Commit

Permalink
fix: ensure proper cleanup of message listeners on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed Jan 22, 2025
1 parent 8185864 commit 554a569
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/server/watch-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ function init (id: number, filePath: string | string[], options: WatchOpts) {
console.log(`watch process ${id} >`, filePath, 'stop')
promiseQueue.length = 0
watcher.close()
process.off('message', onMessage)
process.off('exit', stop)
}

function onMessage (message: Message) {
if (message.id === id && message.type === 'stop') {
stop()
process.off('message', onMessage)
}
}

process.on('message', onMessage)
process.on('exit', stop)
}

process.on('message', (message: Message) => {
Expand Down

0 comments on commit 554a569

Please sign in to comment.