mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
10 lines
275 B
TypeScript
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
|
|
}
|
|
}
|