@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
24 lines (22 loc) • 499 B
text/typescript
import { toIterator, ToIteratorOptions } from '@johngw/stream/sinks/toIterator'
/**
* Turns a `ReadableStream` in to an `AsyncIterable`.
*
* @group Sinks
* @see {@link toArray:function}
* @see {@link toIterator}
* @example
* ```
* for await (const chunk of toIterable(stream)) {
*
* }
* ```
*/
export function toIterable<T>(
stream: ReadableStream<T>,
options?: ToIteratorOptions
): AsyncIterable<T> {
return {
[Symbol.asyncIterator]: () => toIterator(stream, options),
}
}