@rxjs-ninja/rxjs-utility
Version:
Useful utilities for RxJS
35 lines (34 loc) • 1.39 kB
TypeScript
/**
* @packageDocumentation
* @module Utility
*/
import { MonoTypeOperatorFunction } from 'rxjs';
/**
* Returns the source Observable, emitting it through the passed WritableStream and handling the internal
* subscription state and error handling. If passed an
* {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal|AbortSignal} the WritableStream can be ended
* early without ending the entire subscription
*
* @category Streams
*
* @see {@link https://stackblitz.com/edit/rxjs-writable-stream|Writable Stream Demo}
*
* @param stream The Writer object to emit the data to
* @param signal Optional signal used to end the writer without ending the rest of the stream
*
* @example Write an array of Observable values to a WritableStream
* ```ts
* let result = ''
* const stream = new WritableStream({
* write: (chunk) => result += chunk,
* close: () => console.log(result)
* });
*
* const input = ['Hello', ' ', 'RxJS', ' ', 'Ninja'];
* from(input).pipe(toWritableStream(stream)).subscribe();
* ```
* Output: `Hello RxJS Ninja`
*
* @returns Observable that emits the source observable after performing a write to the WritableStream
*/
export declare function toWritableStream<T extends unknown>(stream: WritableStream<T> | WritableStreamDefaultWriter<T>, signal?: AbortSignal): MonoTypeOperatorFunction<T>;