UNPKG

pubsub-ts

Version:

PubSub Messaging Pattern in Typescript

40 lines (39 loc) 1.19 kB
export declare module PubSub { enum NotificationType { standard = 0, priority = 1, urgent = 2, } interface Notification { name: string; body: any; type: NotificationType; } class Subscriber { private standardQueue; private priorityQueue; private interests; private key; private shouldPost; constructor(key?: string); on(eventName: string, callback: Function): void; off(eventName: string): void; getKey(): string; start(): void; pause(): void; post(notification: Notification): void; private processNotifications(); private postNotifications(queue); private postCallback(notification); } class Publisher { private subscribers; add(subscriber: Subscriber): void; delete(subscriber: Subscriber): void; has(key: string): boolean; notify(eventName: string, data: any): void; notifyPriority(eventName: string, data: any): void; notifyUrgent(eventName: string, data: any): void; private sendNotification(eventName, data, type); } }