ConflatedBroadcastChannel

class ConflatedBroadcastChannel<E> : BroadcastChannel<E>

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 trySend always succeeds.

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.

Note: This API is obsolete since 1.5.0. It will be deprecated with warning in 1.6.0 and with error in 1.7.0. It is replaced with StateFlow.

Constructors

ConflatedBroadcastChannel
Link copied to clipboard
common
fun <E> ConflatedBroadcastChannel(value: E)
Creates an instance of this class that already holds a value.
ConflatedBroadcastChannel
Link copied to clipboard
common
fun ConflatedBroadcastChannel()

Functions

cancel
Link copied to clipboard
common
open override fun cancel(cause: CancellationException?)
Cancels this conflated broadcast channel with an optional cause, same as close.
close
Link copied to clipboard
common
open override fun close(cause: Throwable?): Boolean
Closes this channel.
invokeOnClose
Link copied to clipboard
common
open override fun invokeOnClose(handler: Handler)
Registers a handler which is synchronously invoked once the channel is closed or the receiving side of this channel is cancelled.
openSubscription
Link copied to clipboard
common
open override fun openSubscription(): ReceiveChannel<E>
Subscribes to this BroadcastChannel and returns a channel to receive elements from it.
send
Link copied to clipboard
common
open suspend override fun send(element: E)
Sends the value to all subscribed receives and stores this value as the most recent state for future subscribers.
trySend
Link copied to clipboard
common
open override fun trySend(element: E): ChannelResult<Unit>
Sends the value to all subscribed receives and stores this value as the most recent state for future subscribers.

Properties

isClosedForSend
Link copied to clipboard
common
open override val isClosedForSend: Boolean
Returns true if this channel was closed by an invocation of close.
onSend
Link copied to clipboard
common
open override val onSend: SelectClause2<E, SendChannel<E>>
Clause for the select expression of the send suspending function that selects when the element that is specified as the parameter is sent to the channel.
value
Link copied to clipboard
common
val value: E
The most recently sent element to this channel.
valueOrNull
Link copied to clipboard
common
val valueOrNull: E?
The most recently sent element to this channel or null when this class is constructed without initial value and no value was sent yet or if it was closed.

Sources

common source
Link copied to clipboard