UNPKG

@naturalcycles/nodejs-lib

Version:
26 lines (25 loc) 1.44 kB
import type { ReadableOptions } from 'node:stream'; import type { ReadableTyped } from '../stream.model.js'; /** * Convenience function to create a Readable that can be pushed into (similar to RxJS Subject). * Push `null` to it to complete (similar to RxJS `.complete()`). * * Difference from Readable.from() is that this readable is not "finished" yet and allows pushing more to it. * * Caution! * The implementation of this Readable is not fully compliant, * e.g the read() method doesn't return anything, so, it will hang the Node process (or cause it to process.exit(0)) * if read() will be called AFTER everything was pushed and Readable is closed (by pushing `null`). * Beware of it when e.g doing unit testing! Jest prefers to hang (not exit-0). */ export declare function createReadable<T>(items?: Iterable<T>, opt?: ReadableOptions, onRead?: () => void): ReadableTyped<T>; /** * Convenience type-safe wrapper around Readable.from() that infers the Type of input. */ export declare function createReadableFrom<T>(iterable: Iterable<T> | AsyncIterable<T>, opt?: ReadableOptions): ReadableTyped<T>; /** * Allows to "create Readable asynchronously". * Implemented via a proxy Transform, which is created (and returned) eagerly, * and later (when source Readable is created) serves as a pass-through proxy. */ export declare function createReadableFromAsync<T>(fn: () => Promise<ReadableTyped<T>>): ReadableTyped<T>;