BroadcastChannel

interface BroadcastChannel<E> : SendChannel<E>

Broadcast channel is a non-blocking primitive for communication between the sender and multiple receivers that subscribe for the elements using openSubscription function and unsubscribe using ReceiveChannel.cancel function.

See BroadcastChannel() factory function for the description of available broadcast channel implementations.

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 SharedFlow.

Functions

cancel
Link copied to clipboard
common
abstract fun cancel(cause: CancellationException? = null)
Cancels reception of remaining elements from this channel with an optional cause.
openSubscription
Link copied to clipboard
common
abstract fun openSubscription(): ReceiveChannel<E>
Subscribes to this BroadcastChannel and returns a channel to receive elements from it.

Inheritors

ConflatedBroadcastChannel
Link copied to clipboard

Extensions

asFlow
Link copied to clipboard
common
fun <T> BroadcastChannel<T>.asFlow(): Flow<T>
Represents the given broadcast channel as a hot flow.
consume
Link copied to clipboard
common
inline fun <E, R> BroadcastChannel<E>.consume(block: ReceiveChannel<E>.() -> R): R
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.
consumeEach
Link copied to clipboard
common
inline suspend fun <E> BroadcastChannel<E>.consumeEach(action: (E) -> Unit)
Subscribes to this BroadcastChannel and performs the specified action for each received element.

Sources

common source
Link copied to clipboard