abort-controller-x-rxjs
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.0 • Public • Published

    abort-controller-x-rxjs npm version

    Abortable helpers for RxJS.

    This is a companion package of abort-controller-x.

    Installation

    yarn add abort-controller-x-rxjs
    

    API

    defer

    function defer<R extends ObservableInput<any> | void>(
      observableFactory: (signal: AbortSignal) => R,
    ): Observable<ObservedValueOf<R>>;

    Like original defer from RxJS, but aborts passed function when unsubscribed.

    firstValueFrom

    function firstValueFrom<T, D>(
      signal: AbortSignal,
      source: Observable<T>,
      config: FirstValueFromConfig<D>,
    ): Promise<T | D>;
    function firstValueFrom<T>(
      signal: AbortSignal,
      source: Observable<T>,
    ): Promise<T>;
    
    interface FirstValueFromConfig<T> {
      defaultValue: T;
    }

    Like original firstValueFrom from RxJS, but accepts AbortSignal. When that signal is aborted, unsubscribes from the observable and throws AbortError.

    lastValueFrom

    function lastValueFrom<T, D>(
      signal: AbortSignal,
      source: Observable<T>,
      config: LastValueFromConfig<D>,
    ): Promise<T | D>;
    function lastValueFrom<T>(
      signal: AbortSignal,
      source: Observable<T>,
    ): Promise<T>;
    
    interface LastValueFromConfig<T> {
      defaultValue: T;
    }

    Like original lastValueFrom from RxJS, but accepts AbortSignal. When that signal is aborted, unsubscribes from the observable and throws AbortError.

    fromAsyncGenerator

    function fromAsyncGenerator<T>(
      fn: (signal: AbortSignal) => AsyncIterable<T>,
    ): Observable<T>;

    Turns abortable async generator to observable.

    Install

    npm i abort-controller-x-rxjs

    DownloadsWeekly Downloads

    401

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    29.2 kB

    Total Files

    41

    Last publish

    Collaborators

    • aikoven