@graphql-hive/pubsub
Version:
33 lines (30 loc) • 1.81 kB
TypeScript
import { DisposableSymbols } from '@whatwg-node/disposablestack';
type TopicDataMap = Record<string, any>;
interface HivePubSub<Data extends TopicDataMap = TopicDataMap> {
/** @deprecated Please use {@link subscribedTopics} if implemented instead. This method will be removed in next major release. */
getEventNames(): Iterable<keyof Data>;
/** @important This method will be required starting next major release. */
subscribedTopics?(): Iterable<keyof Data>;
publish<Topic extends keyof Data>(topic: Topic, data: Data[Topic]): void;
subscribe<Topic extends keyof Data>(topic: Topic, listener: PubSubListener<Data, Topic>): number;
unsubscribe(subId: number): void;
asyncIterator<Topic extends keyof Data>(topic: Topic): AsyncIterable<Data[Topic]>;
/** @important This method will be required starting next major release. */
dispose?(): void;
/** @important This method will be required starting next major release. */
[DisposableSymbols.dispose]?(): void;
}
type PubSubListener<Data extends TopicDataMap, Topic extends keyof Data> = (data: Data[Topic]) => void;
declare class PubSub<Data extends TopicDataMap = TopicDataMap> implements HivePubSub<Data> {
#private;
/** @deprecated Please use {@link subscribedTopics} instead. */
getEventNames(): MapIterator<keyof Data>;
subscribedTopics(): MapIterator<keyof Data>;
publish<Topic extends keyof Data>(topic: Topic, data: Data[Topic]): void;
subscribe<Topic extends keyof Data>(topic: Topic, listener: PubSubListener<Data, Topic>): number;
unsubscribe(subId: number): void;
asyncIterator<Topic extends keyof Data>(topic: Topic): AsyncIterable<Data[Topic]>;
dispose(): void;
[DisposableSymbols.dispose](): void;
}
export { type HivePubSub, PubSub, type PubSubListener };