ts-event-bus
Version:
Distributed messaging in Typescript
38 lines • 1.61 kB
TypeScript
import { Transport } from './Transport';
import { Handler } from './Handler';
interface SlotConfig {
noBuffer?: boolean;
autoReconnect?: boolean;
}
export declare const defaultSlotConfig: {
noBuffer: boolean;
autoReconnect: boolean;
};
export type LazyCallback = (param: string) => void;
export type Unsubscribe = () => void;
/**
* Represents an event shared by two modules.
*
* A module can trigger the event by calling the slot. This will return a promise,
* which will be resolved with the response sent by the other module if applicable.
*
* The slot can also be subscribed to, by using the `on` property.
*/
export interface Slot<RequestData = null, ResponseData = void> {
(param: string, requestData: RequestData): Promise<ResponseData>;
(requestData: RequestData): Promise<ResponseData>;
on(param: string, handler: Handler<RequestData, ResponseData>): Unsubscribe;
on(handler: Handler<RequestData, ResponseData>): Unsubscribe;
lazy(connect: LazyCallback, disconnect: LazyCallback): Unsubscribe;
config?: SlotConfig;
slotName: string;
}
/**
* A shorthand function used to declare slots in event bus object literals
* It returns a fake slot, that will throw if triggered or subscribed to.
* Slots need to be connected in order to be functional.
*/
export declare function slot<RequestData = void, ResponseData = void>(config?: SlotConfig): Slot<RequestData, ResponseData>;
export declare function connectSlot<T = void, T2 = void>(slotName: string, transports: Transport[], config?: SlotConfig): Slot<T, T2>;
export {};
//# sourceMappingURL=Slot.d.ts.map