arrow-fx-coroutines / arrow.fx.coroutines.stream.concurrent / Topic

Topic

class ~~Topic~~<A> Deprecated: Stream is deprecated in favor of KotlinX Flow. Use Channel

Asynchronous Topic.

Topic allows you to distribute A published by arbitrary number of publishers to arbitrary number of subscribers.

Topic has built-in back-pressure support implemented as maximum bound (maxQueued) that a subscriber is allowed to enqueue. Once that bound is hit, publishing may semantically block until the lagging subscriber consumes some of its queued elements.

Additionally the subscriber has possibility to terminate whenever size of enqueued elements is over certain size by using subscribeSize.

Functions

publish Publishes elements from source of A to this topic. Pipe equivalent of publish1.fun publish(): Pipe<A, Unit>
publish1 Publishes one A to topic.suspend fun publish1(a: A): Unit
subscribe Subscribes for A values that are published to this topic.fun subscribe(maxQueued: Int): Stream<A>
subscribers Signal of current active subscribers.fun subscribers(): Stream<Int>
subscribeSize Like subscribe but emits an approximate number of queued elements for this subscription with each emitted A value.fun subscribeSize(maxQueued: Int): Stream<Pair<A, Int>>

Companion Object Functions

invoke suspend operator fun <A> invoke(initial: A): Topic<A>

Do you like Arrow?

Arrow Org
<