UNPKG

@edifice.io/client

Version:
29 lines (28 loc) 837 B
/** * Simple in-memory channel implementation. * This is intentionally synchronous (listeners are invoked in insertion order). */ export declare class SimpleChannel<T = any> { private static channels; /** * Get a channel by name (create it if it doesn't exist). * @param name of the channel * @returns the channel instance */ static getChannel<T = any>(name: string): SimpleChannel<T>; private readonly name; private listeners; private constructor(); /** * Add a listener and return a revocation function to remove it. */ listen(handler: (msg: T) => void): () => void; /** * Publish a message to all listeners. */ publish(message: T): void; /** * Close this channel: remove listeners and unregister from global map. */ close(): void; }