mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-12 02:19:55 +08:00
refactor pipeWriteRegardlessError - use error event to handle error
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import * as fs from 'fs'
|
||||
import { type Stream } from 'stream'
|
||||
const pipeSet = new WeakSet<Stream>()
|
||||
|
||||
export const pipeWriteRegardlessError = async (
|
||||
pipe: fs.WriteStream | null,
|
||||
chunk: unknown,
|
||||
option?
|
||||
) => {
|
||||
return new Promise((resolve) => {
|
||||
// debugger
|
||||
pipe?.write(chunk, option, (error) => {
|
||||
if (error) {
|
||||
console.log('pipe.write Error', error)
|
||||
}
|
||||
resolve(undefined)
|
||||
if (pipe && !pipeSet.has(pipe)) {
|
||||
pipeSet.add(pipe)
|
||||
pipe.on('error', (error) => {
|
||||
console.log('pipe.write Error', error)
|
||||
})
|
||||
})
|
||||
}
|
||||
return pipe?.write(chunk, option, () => {})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user