@kephas/core
Version:
Provides a common infrastructure for all the other Kephas Framework components: ambient services, dynamic reflection, composition, application management, and others.
51 lines (50 loc) • 1.6 kB
TypeScript
import { Disposable } from "../disposable";
import { Logger } from "../logging/logger";
import { Context } from "../services/context";
import { AbstractType, Type } from "../type";
/**
* Singleton application service handling in-process event publishing/subscribing.
*
* @export
* @class EventHub
*/
export declare class EventHub {
private _subscriptions;
private _logger;
/**
* Creates an instance of EventHub.
*
* @param {Logger} logger The logger.
* @memberof EventHub
*/
constructor(logger?: Logger);
/**
* Gets the logger.
*
* @readonly
* @protected
* @type {Logger}
* @memberof EventHub
*/
protected get logger(): Logger;
/**
* Publishes the event asynchronously to its subscribers.
*
* @param {*} event The event.
* @param {Context} [context] Optional. The context.
* @returns {Promise<any>} The promise.
* @memberof EventHub
*/
publishAsync(event: any, context?: Context): Promise<any>;
/**
* Subscribes to the event(s) matching the criteria.
*
* @template T The event type.
* @param {(AbstractType | Type<T>)} match Specifies the match type.
* @param {((event: T, context?: Context) => Promise<any> | void)} callback The callback.
* @returns {Disposable} A disposable event subscription.
* @memberof EventHub
*/
subscribe<T>(match: AbstractType | Type<T>, callback: (event: T, context?: Context) => Promise<any> | void): Disposable;
private _getMatch;
}