fix: ensure proper cleanup of message listeners on stop

This commit is contained in:
purocean
2025-01-22 19:44:13 +08:00
parent 81858644f5
commit 554a569133
+3 -1
View File
@@ -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) => {