BroadcastChannel

Deprecated

BroadcastChannel is deprecated in the favour of SharedFlow and is no longer supported

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 and deprecated for removal since 1.7.0 It is replaced with SharedFlow.

Inheritors

Functions

Link copied to clipboard

Represents the given broadcast channel as a hot flow. Every flow collector will trigger a new broadcast channel subscription.

Link copied to clipboard
abstract fun cancel(cause: CancellationException? = null)

Cancels reception of remaining elements from this channel with an optional cause. This function closes the channel with the specified cause (unless it was already closed), removes all buffered sent elements from it, and cancels all open subscriptions. A cause can be used to specify an error message or to provide other details on a cancellation reason for debugging purposes.

Link copied to clipboard

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.

Link copied to clipboard
inline suspend fun <E> BroadcastChannel<E>.consumeEach(action: (E) -> Unit)

Subscribes to this BroadcastChannel and performs the specified action for each received element.

Link copied to clipboard

Subscribes to this BroadcastChannel and returns a channel to receive elements from it. The resulting channel shall be cancelled to unsubscribe from this broadcast channel.