once pipe for process communication get bad, exit process immediately

This commit is contained in:
geekgeekrun
2024-03-24 14:58:34 +08:00
parent 3a31f7d186
commit fdf9081a8f

View File

@@ -1,5 +1,6 @@
import * as fs from 'fs'
import { type Stream } from 'stream'
import { app } from 'electron'
const pipeSet = new WeakSet<Stream>()
export const pipeWriteRegardlessError = async (
@@ -10,8 +11,14 @@ export const pipeWriteRegardlessError = async (
if (pipe && !pipeSet.has(pipe)) {
pipeSet.add(pipe)
pipe.on('error', (error) => {
console.log('pipe.write Error', error)
void error
})
}
return pipe?.write(chunk, option, () => {})
return pipe?.write(chunk, option, (error) => {
if (error) {
console.log('pipe.write Error', error)
app.exit(1)
process.exit(1)
}
})
}