foxts
Version:
Opinionated collection of common TypeScript utils by @SukkaW
19 lines (16 loc) • 570 B
TypeScript
import { Writable } from 'node:stream';
/**
* A small utility function for writing chunk to a stream, and only return promise when needed (stream backpressure)
*
* ```ts
* const writeStream = fs.createWriteStream(outputFile);
* for (const line of source) {
* const p = asyncWriteToStream(writeStream, line + '\n');
* if (p) {
* // eslint-disable-next-line no-await-in-loop -- stream backpressure
* await p;
* }
* }
*/
declare function asyncWriteToStream<T>(stream: Writable, chunk: T): Promise<unknown> | null;
export { asyncWriteToStream };