github
DocsBlog
fontcolor_theme
package

API @deepkit/core-rxjs

npm install @deepkit/core-rxjs

Classes

AsyncSubscription [source]
export class AsyncSubscription {
    constructor(private cb: () => Promise<void>);
    async unsubscribe(): Promise<void>;
}
Subscriptions [source]
export class Subscriptions {
    readonly list: Subscription[];
    constructor(protected teardown?: () => void | Promise<void>);
    unsubscribe();
}

RXJS subscription collection, to easily collect multiple subscriptions and unsubscribe all at once. Added subscriptions are automatically removed when they get unsubscribed.

ObserverTimer [source]
export class ObserverTimer extends Timer {
    constructor(protected observer: Observer<any>);
    setTimeout(cb: () => void, timeout: number): any;
}

Allows to create Timer which is deactivated automatically when the observer is stopped.

ProgressTrackerGroup [source]
export class ProgressTrackerGroup {
    stopCallbacks: (() => void)[];
    constructor(public state: ProgressTrackerState);
    changed();
    /**
     * Registers a callback that is called when the progress is stopped.
     */
    onStop(callback: () => void);
    stop();
    /**
     * Number between 0 and 1.
     */
    get progress(): number;
    /**
     * Total number of items to process.
     */
    get total(): number;
    /**
     * True if the progress is finished (done === total).
     * Same as progress === 1.
     */
    get finished();
    /**
     * True if the progress is running (finished === false && stopped === false).
     */
    get running();
    /**
     * True if the progress is ended (finished === true || stopped === true).
     */
    get ended();
    /**
     * True if the progress is stopped (stopped === true), but might not be finished.
     */
    get stopped();
    get message(): string;
    get done(): number;
}
ProgressTracker [source]
export class ProgressTracker extends BehaviorSubject<ProgressTrackerState[]> {
    groups: ProgressTrackerGroup[];
    changed;
    constructor(states: ProgressTrackerState[] = []);
    next(states: ProgressTrackerState[]);
    stop();
    track(message: string = , total: number, current: number = ): ProgressTrackerGroup;
    get progress(): number;
    /**
     * True if the progress is finished (done === total).
     * Same as progress === 1.
     */
    get finished(): boolean;
    /**
     * True if the progress is running (finished === false && stopped === false).
     */
    get running(): boolean;
    /**
     * True if the progress is ended (finished === true || stopped === true).
     */
    get ended(): boolean;
    /**
     * True if the progress is stopped (stopped === true), but might not be finished.
     */
    get stopped();
    get done(): number;
    get total(): number;
    get current(): ProgressTrackerGroup | undefined;
}

This class allows to track multiple progress states.

Natively supported as return type in

ProgressTrackerWatcher [source]
export class ProgressTrackerWatcher<T extends ProgressTracker = ProgressTracker> extends BehaviorSubject<T> {
}

Functions

watchClosed [source]
(observer: Observer<any>): { closed: boolean; }
isSubject [source]
(v: any): v is Subject<any>
isBehaviorSubject [source]
(v: any): v is BehaviorSubject<any>
subscriptionToPromise [source]
<T>(subscription: Subscription): Promise<void>
nextValue [source]
<T>(o: Observable<T>): Promise<T>
observableToPromise [source]
<T>(o: Observable<T>, next?: (data: T) => void): Promise<T>
promiseToObservable [source]
<T>(o: () => Promise<T>): Observable<T>
tearDown [source]
(teardown: TeardownLogic): Promise<void>
throttleMessages [source]
<T, R>(observable: Observable<T>, handler: (messages: T[]) => Promise<R>, options?: Partial<{ maxWait: number; batchSize: number; }>): Promise<R[]>

Handles incoming messages in batches. The handler is called when the observable completes or when a certain time passed since the last message.

This makes sure the handler is awaited before the next batch is processed.

maxWait in milliseconds, this makes sure every maxWait ms the handler is called with the current messages if there are any. batchSize this is the maximum amount of messages that are passed to the handler.

decoupleSubject [source]
<T extends Observable<any> | undefined>(observable: T): T

Clone a given subject (BehaviourSubject or ProgressTracker or Subject) and decouple it from the source, so that when the new object is completed or errored, the source is not affected.

This is handy if you want to hand out a subject to a consumer, but you don't want the consumer to be able to complete or error the subject, which is usually requires for RPC controllers.

watchProgressTracker [source]
<T extends ProgressTracker>(tracker: T): ProgressTrackerWatcher<T>

Turns a ProgressTracker into a BehaviorSubject

Types

ProgressTrackerState [source]
interface ProgressTrackerState {
    total: number;
    done: number;
    message: string;
    speed: number;
    stopped: boolean;
}