UNPKG

1.88 kBTypeScriptView Raw
1import { Observable, ObservableLike, SubscriptionObserver } from "observable-fns";
2declare type Initializer<T> = (observer: SubscriptionObserver<T>) => UnsubscribeFn | void;
3declare type Thenable<T> = {
4 then: (onFulfilled?: (value: T) => any, onRejected?: (error: any) => any) => any;
5};
6declare type UnsubscribeFn = () => void;
7/**
8 * Creates a hybrid, combining the APIs of an Observable and a Promise.
9 *
10 * It is used to proxy async process states when we are initially not sure
11 * if that async process will yield values once (-> Promise) or multiple
12 * times (-> Observable).
13 *
14 * Note that the observable promise inherits some of the observable's characteristics:
15 * The `init` function will be called *once for every time anyone subscribes to it*.
16 *
17 * If this is undesired, derive a hot observable from it using `makeHot()` and
18 * subscribe to that.
19 */
20export declare class ObservablePromise<T> extends Observable<T> implements Promise<T> {
21 private initHasRun;
22 private fulfillmentCallbacks;
23 private rejectionCallbacks;
24 private firstValue;
25 private firstValueSet;
26 private rejection;
27 private state;
28 readonly [Symbol.toStringTag]: "[object ObservablePromise]";
29 constructor(init: Initializer<T>);
30 private onNext;
31 private onError;
32 private onCompletion;
33 then<TResult1 = T, TResult2 = never>(onFulfilledRaw?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onRejectedRaw?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
34 catch<Result = never>(onRejected: ((error: Error) => Promise<Result> | Result) | null | undefined): Promise<Result>;
35 finally(onCompleted?: (() => void) | null | undefined): Promise<T>;
36 static from<T>(thing: Observable<T> | ObservableLike<T> | ArrayLike<T> | Thenable<T>): ObservablePromise<T>;
37}
38export {};