Danish Arora fdd9dc44a4
feat(filter)!: new simpler filter API (#2092)
* chore: rename IReceiver subscribe

* feat!: new `subscribe() API that only takes in decoders and callback

* chore: `to_async_iterator` uses new function name

* chore: make `createSubscription` private, and shorten error handling

* chore: update subscribe return type

* tests: use new API

* fix: tests
2024-08-05 15:52:58 +05:30

23 lines
663 B
TypeScript

import type { IDecodedMessage, IDecoder } from "./message.js";
import type {
ContentTopic,
IAsyncIterator,
PubsubTopic,
Unsubscribe
} from "./misc.js";
import type { Callback } from "./protocols.js";
export type ActiveSubscriptions = Map<PubsubTopic, ContentTopic[]>;
export interface IReceiver {
toSubscriptionIterator: <T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[]
) => Promise<IAsyncIterator<T>>;
subscribeWithUnsubscribe: SubscribeWithUnsubscribe;
}
type SubscribeWithUnsubscribe = <T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[],
callback: Callback<T>
) => Unsubscribe | Promise<Unsubscribe>;