ConflatedBroadcastChannel
class ConflatedBroadcastChannel<E> : BroadcastChannel<E>
(source)Platform and version requirements: JVM
Broadcasts the most recently sent element (aka value) to all openSubscription subscribers.
Back-to-send sent elements are conflated – only the the most recently sent value is received,
while previously sent elements are lost.
Every subscriber immediately receives the most recently sent element.
Sender to this broadcast channel never suspends and offer always returns true
.
A secondary constructor can be used to create an instance of this class that already holds a value.
This channel is also created by BroadcastChannel(Channel.CONFLATED)
factory function invocation.
This implementation is fully lock-free. In this implementation opening and closing subscription takes O(N) time, where N is the number of subscribers.
Constructors
ConflatedBroadcastChannel(value: E) Creates an instance of this class that already holds a value. ConflatedBroadcastChannel() Broadcasts the most recently sent element (aka value) to all openSubscription subscribers. |
Properties
val isClosedForSend: Boolean Returns |
|
val isFull: Boolean Returns |
|
val onSend: SelectClause2<E, SendChannel<E>> Clause for select expression of send suspending function that selects when the element that is specified as parameter is sent to the channel. When the clause is selected the reference to this channel is passed into the corresponding block. |
|
val value: E The most recently sent element to this channel. |
|
val valueOrNull: E? The most recently sent element to this channel or |
Functions
Closes this channel with an optional exceptional cause.
This is an idempotent operation – repeated invocations of this function have no effect and return |
|
Sends the value to all subscribed receives and stores this value as the most recent state for
future subscribers. This implementation always returns |
|
fun openSubscription(): SubscriptionReceiveChannel<E> Subscribes to this BroadcastChannel and returns a channel to receive elements from it. The resulting channel shall be closed to unsubscribe from this broadcast channel. |
|
Sends the value to all subscribed receives and stores this value as the most recent state for future subscribers. This implementation never suspends. It throws exception if the channel isClosedForSend (see close for details). |
Extension Functions
fun <E, R> BroadcastChannel<E>.consume( Opens subscription to this BroadcastChannel and makes sure that the given block consumes all elements from it by always invoking cancel after the execution of the block. |
|
suspend fun <E> BroadcastChannel<E>.consumeEach( Subscribes to this BroadcastChannel and performs the specified action for each received element. |
|
fun <E> SendChannel<E>.sendBlocking(element: E): Unit Adds element into to this channel, blocking the caller while this channel Channel.isFull, or throws exception if the channel Channel.isClosedForSend (see Channel.close for details). |