mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
10 lines
279 B
TypeScript
10 lines
279 B
TypeScript
import type { Writable } from 'node:stream';
|
|
import { once } from 'node:events';
|
|
|
|
export const asyncWriteToStream = <T>(stream: Writable, chunk: T) => {
|
|
const res = stream.write(chunk);
|
|
if (!res) {
|
|
return once(stream, 'drain'); // returns a promise only if needed
|
|
}
|
|
};
|