UNPKG

725 BTypeScriptView Raw
1/// <reference types="node" />
2import { EventEmitter } from 'events';
3import { PubSubEngine } from './pubsub-engine';
4export interface PubSubOptions {
5 eventEmitter?: EventEmitter;
6}
7export declare class PubSub<Events extends {
8 [event: string]: unknown;
9} = Record<string, never>> extends PubSubEngine {
10 protected ee: EventEmitter;
11 private subscriptions;
12 private subIdCounter;
13 constructor(options?: PubSubOptions);
14 publish<K extends keyof Events>(triggerName: K & string, payload: Events[K] extends never ? any : Events[K]): Promise<void>;
15 subscribe<K extends keyof Events>(triggerName: K & string, onMessage: (...args: any[]) => void): Promise<number>;
16 unsubscribe(subId: number): void;
17}