@rxjs-ninja/rxjs-utility
Version:
Useful utilities for RxJS
39 lines (38 loc) • 1.47 kB
TypeScript
/**
* @packageDocumentation
* @module Utility
*/
import { Observable } from 'rxjs';
/**
* Creates an Observable source from a ReadableStream source that will emit any
* values emitted by the stream.
*
* @category Streams
*
* @see {@link https://stackblitz.com/edit/rxjs-readable-stream|StreamAPI Number Stream}
* @see {@link https://stackblitz.com/edit/rxjs-readable-stream-fetch|Fetch + StreamAPI Demo}
*
* @param stream The ReadableStream to subscribe to
* @param signal Optional {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal|AbortSignal} to provide
* to the underlying stream
* @param queueStrategy Optional strategy for backpressure queueing
* @param throwEndAsError Optional to return an error when the `AbortSignal` has been fired instead of just closing
*
* @example Create a ReadableStream of `0` to `100` and convert to an Observable
* ```ts
* const stream = new ReadableStream({
* start: (controller) => {
* for (let i = 0; i <100; i++) {
* controller.enqueue(i)
* }
* controller.close();
* }
* });
*
* fromReadableStream(stream).pipe(reduce((a, b) => a + b)).subscribe();
* ```
* Output: `4950`
*
* @returns Observable that emits from a ReadableStream source
*/
export declare function fromReadableStream<T extends unknown>(stream: ReadableStream<T>, signal?: AbortSignal, queueStrategy?: QueuingStrategy, throwEndAsError?: boolean): Observable<T>;