Abortable helpers for RxJS.
This is a companion package of
abort-controller-x
.
yarn add abort-controller-x-rxjs
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.
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
.
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
.
function fromAsyncGenerator<T>(
fn: (signal: AbortSignal) => AsyncIterable<T>,
): Observable<T>;
Turns abortable async generator to observable.