tdlib-native
Version:
🚀 Telegram TDLib native nodejs wrapper
62 lines (61 loc) • 1.38 kB
TypeScript
export type Subscription<T> = (value: T) => void;
export type Unsubscribe = () => void;
type Observer<T> = (subscriber: Subscriber<T>) => Unsubscribe;
export type Observable<T> = {
subscribe(handler: Subscription<T>): Unsubscribe;
toRxObserver(): (subscriber: Subscriber<T>) => Unsubscribe;
};
type Subscriber<T> = {
next(value?: T): void;
error?(error: any): void;
complete?(): void;
};
/**
*
*
* @export
* @class EventBus
* @implements {Observable<T>}
* @template T
*/
export declare class EventBus<T> implements Observable<T> {
private readonly _subscriptions;
private readonly _onComplete;
private _completed;
/**
*
*
* @param {T} value
* @returns {this}
* @memberof EventBus
*/
emit(value: T): this;
/**
*
*
* @param {Subscription<T>} handler
* @returns {Unsubscribe} {Unsubscribe}
* @memberof EventBus
*/
subscribe(handler: Subscription<T>): Unsubscribe;
/**
*
*
* @memberof EventBus
* @returns {void}
*/
complete(): void;
/**
*
*
* @returns {Observer<T>}
* @example
* import { Observable } from "rxjs";
*
* const bus = new EventBus<number>();
* const observable = new Observable(bus.toRxObserver());
* // Observable<number>
*/
toRxObserver(): Observer<T>;
}
export {};