Surge_by_SukkaW/Build/lib/async-write-to-stream.ts
2024-10-10 21:40:56 +08:00

10 lines
275 B
TypeScript

import type { Writable } from 'node:stream';
import { once } from 'node:events';
export function asyncWriteToStream<T>(stream: Writable, chunk: T) {
const res = stream.write(chunk);
if (!res) {
return once(stream, 'drain'); // returns a promise only if needed
}
}