UNPKG

@thi.ng/transducers-async

Version:

Async versions of various highly composable transducers, reducers and iterators

36 lines 1.38 kB
import type { Fn } from "@thi.ng/api"; import { MSub } from "./mult.js"; export declare const pubsub: <K, V>(src: AsyncIterable<V>, topicFn: Fn<V, K>) => PubSub<K, V>; export declare class PubSub<K, V> { src: AsyncIterable<V>; topicFn: Fn<V, K>; protected topics: Map<K, MSub<V>[]>; protected isActive: boolean; constructor(src: AsyncIterable<V>, topicFn: Fn<V, K>); /** * Creates a new subscription (aka custom `AsyncIterable`) which will * receive any future values from `src` matching given topic `id`. The * returned subscription can be removed again via * {@link PubSub.unsubscribeTopic}. */ subscribeTopic(id: K): AsyncIterable<V>; /** * Similar to {@link PubSub.subscribeTopic}, but for one-off event handling. * Creates a new subscription for topic `id` and waits for next value. Once * received, it immediately unsubscribes again and then calls `fn` with * value. * * @param id * @param fn */ subscribeOnce(id: K, fn: Fn<V, void>): void; /** * Attempts to remove given child subscription (presumably created via * {@link PubSub.subscribeTopic}). Returns true if removal was successful. * * @param sub */ unsubscribeTopic(id: K, sub: AsyncIterable<V>): boolean; protected process(): Promise<void>; } //# sourceMappingURL=pubsub.d.ts.map