mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-05 07:27:35 +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 * as fs from 'fs'
|
||||||
|
import { type Stream } from 'stream'
|
||||||
|
const pipeSet = new WeakSet<Stream>()
|
||||||
|
|
||||||
export const pipeWriteRegardlessError = async (
|
export const pipeWriteRegardlessError = async (
|
||||||
pipe: fs.WriteStream | null,
|
pipe: fs.WriteStream | null,
|
||||||
chunk: unknown,
|
chunk: unknown,
|
||||||
option?
|
option?
|
||||||
) => {
|
) => {
|
||||||
return new Promise((resolve) => {
|
if (pipe && !pipeSet.has(pipe)) {
|
||||||
// debugger
|
pipeSet.add(pipe)
|
||||||
pipe?.write(chunk, option, (error) => {
|
pipe.on('error', (error) => {
|
||||||
if (error) {
|
console.log('pipe.write Error', error)
|
||||||
console.log('pipe.write Error', error)
|
|
||||||
}
|
|
||||||
resolve(undefined)
|
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
return pipe?.write(chunk, option, () => {})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user