ReceiveChannel
Receiver's interface to Channel.
Functions
Cancels reception of remaining elements from this channel with an optional cause. This function closes the channel and removes all buffered sent elements from it.
Returns a new iterator to receive elements from this channel using a for
loop. Iteration completes normally when the channel is closed for receive
without a cause and throws the original close cause exception if the channel has failed.
Retrieves and removes an element from this channel if it's not empty, or suspends the caller while the channel is empty, or throws a ClosedReceiveChannelException if the channel is closed for receive
. If the channel was closed because of an exception, it is called a failed channel and this function will throw the original close cause exception.
Retrieves and removes an element from this channel if it's not empty, or suspends the caller while this channel is empty. This method returns ChannelResult with the value of an element successfully retrieved from the channel or the close cause if the channel was closed. Closed cause may be null
if the channel was closed normally. The result cannot be failed without being closed.
Retrieves and removes an element from this channel if it's not empty, returning a successful result, returns failed result if the channel is empty, and closed result if the channel is closed.
Properties
Returns true
if this channel was closed by invocation of close on the SendChannel side and all previously sent items were already received. This means that calling receive will result in a ClosedReceiveChannelException. If the channel was closed because of an exception, it is considered closed, too, but is called a failed channel. All suspending attempts to receive an element from a failed channel throw the original close cause exception.
Returns true
if the channel is empty (contains no elements), which means that an attempt to receive will suspend. This function returns false
if the channel is closed for receive
.
Clause for the select expression of the receive suspending function that selects with the element received from the channel. The select invocation fails with an exception if the channel is closed for receive
(see close for details).
Clause for the select expression of the onReceiveCatching suspending function that selects with the ChannelResult with a value that is received from the channel or with a close cause if the channel is closed for receive
.
Inheritors
Extensions
Broadcasts all elements of the channel. This function consumes all elements of the original ReceiveChannel.
Represents the given receive channel as a hot flow and consumes the channel on the first collection from this flow. The resulting flow can be collected just once and throws IllegalStateException when trying to collect it more than once.
This function is deprecated in the favour of ReceiveChannel.onReceiveCatching
Represents the given receive channel as a hot flow and receives from the channel in fan-out fashion every time this flow is collected. One element will be emitted to one collector only.