ReceiveChannel
interface ReceiveChannel<out E>
(source)Receiver’s interface to Channel.
Properties
abstract val isClosedForReceive: Boolean Returns |
|
abstract val isEmpty: Boolean Returns |
|
abstract val onReceive: SelectClause1<E> 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 |
Functions
abstract fun cancel( 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. |
|
abstract operator fun iterator(): ChannelIterator<E> Returns a new iterator to receive elements from this channel using a |
|
abstract fun poll(): E? Retrieves and removes an element from this channel if its not empty, or returns |
|
abstract suspend fun receive(): E 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 |
Extension Functions
suspend fun <E> ReceiveChannel<E>. Returns |
|
suspend fun <E> ReceiveChannel<E>. Returns suspend fun <E> ReceiveChannel<E>. Returns |
|
Returns a Map containing key-value pairs provided by transform function applied to elements of the given channel. |
|
Returns a Map containing the elements from the given channel indexed by the key returned from keySelector function applied to each element. suspend fun <E, K, V> ReceiveChannel<E>. Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given channel. |
|
suspend fun <E, K, M : MutableMap<in K, in E>> ReceiveChannel<E>. Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function applied to each element of the given channel and value is the element itself. suspend fun <E, K, V, M : MutableMap<in K, in V>> ReceiveChannel<E>. Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function and and value is provided by the valueTransform function applied to elements of the given channel. |
|
suspend fun <E, K, V, M : MutableMap<in K, in V>> ReceiveChannel<E>. Populates and returns the destination mutable map with key-value pairs provided by transform function applied to each element of the given channel. |
|
fun <E> ReceiveChannel<E>.broadcast( Broadcasts all elements of the channel. This function consumes all elements of the original ReceiveChannel. |
|
fun <E, R> ReceiveChannel<E>.consume( Makes sure that the given block consumes all elements from the given channel by always invoking cancel after the execution of the block. |
|
fun <T> ReceiveChannel<T>.consumeAsFlow(): Flow<T> 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. |
|
suspend fun <E> ReceiveChannel<E>.consumeEach( Performs the given action for each received element and cancels
the channel after the execution of the block.
If you need to iterate over the channel without consuming it, a regular |
|
suspend fun <E> ReceiveChannel<E>. Performs the given action for each received element. |
|
fun ReceiveChannel<*>. Returns a CompletionHandler that invokes cancel on the ReceiveChannel with the corresponding cause. See also ReceiveChannel.consume. |
|
suspend fun <E> ReceiveChannel<E>. Returns the number of elements in this channel. suspend fun <E> ReceiveChannel<E>. Returns the number of elements matching the given predicate. |
|
fun <E> ReceiveChannel<E>. Returns a channel containing only distinct elements from the given channel. |
|
fun <E, K> ReceiveChannel<E>. Returns a channel containing only elements from the given channel having distinct keys returned by the given selector function. |
|
fun <E> ReceiveChannel<E>. Returns a channel containing all elements except first n elements. |
|
fun <E> ReceiveChannel<E>. Returns a channel containing all elements except first elements that satisfy the given predicate. |
|
suspend fun <E> ReceiveChannel<E>. Returns an element at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this channel. |
|
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this channel. |
|
suspend fun <E> ReceiveChannel<E>. Returns an element at the given index or |
|
fun <E> ReceiveChannel<E>. Returns a channel containing only elements matching the given predicate. |
|
fun <E> ReceiveChannel<E>. Returns a channel containing only elements matching the given predicate. |
|
suspend fun <E, C : MutableCollection<in E>> ReceiveChannel<E>. Appends all elements matching the given predicate to the given destination. |
|
fun <E> ReceiveChannel<E>. Returns a channel containing all elements not matching the given predicate. |
|
fun <E : Any> ReceiveChannel<E?>. Returns a channel containing all elements that are not |
|
suspend fun <E : Any, C : MutableCollection<in E>> ReceiveChannel<E?>. Appends all elements that are not |
|
suspend fun <E, C : MutableCollection<in E>> ReceiveChannel<E>. Appends all elements not matching the given predicate to the given destination. |
|
suspend fun <E, C : MutableCollection<in E>> ReceiveChannel<E>. Appends all elements matching the given predicate to the given destination. |
|
suspend fun <E> ReceiveChannel<E>. Returns the first element matching the given predicate, or |
|
suspend fun <E> ReceiveChannel<E>. Returns the last element matching the given predicate, or |
|
suspend fun <E> ReceiveChannel<E>. Returns first element. suspend fun <E> ReceiveChannel<E>. Returns the first element matching the given predicate. |
|
suspend fun <E> ReceiveChannel<E>. Returns the first element, or suspend fun <E> ReceiveChannel<E>. Returns the first element matching the given predicate, or |
|
fun <E, R> ReceiveChannel<E>. Returns a single channel of all elements from results of transform function being invoked on each element of original channel. |
|
Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element. |
|
suspend fun <E, R> ReceiveChannel<E>. Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element with its index in the original channel. |
|
Groups elements of the original channel by the key returned by the given keySelector function applied to each element and returns a map where each group key is associated with a list of corresponding elements. suspend fun <E, K, V> ReceiveChannel<E>. Groups values returned by the valueTransform function applied to each element of the original channel by the key returned by the given keySelector function applied to the element and returns a map where each group key is associated with a list of corresponding values. |
|
suspend fun <E, K, M : MutableMap<in K, MutableList<E>>> ReceiveChannel<E>. Groups elements of the original channel by the key returned by the given keySelector function applied to each element and puts to the destination map each group key associated with a list of corresponding elements. suspend fun <E, K, V, M : MutableMap<in K, MutableList<V>>> ReceiveChannel<E>. Groups values returned by the valueTransform function applied to each element of the original channel by the key returned by the given keySelector function applied to the element and puts to the destination map each group key associated with a list of corresponding values. |
|
suspend fun <E> ReceiveChannel<E>. Returns first index of element, or -1 if the channel does not contain element. |
|
suspend fun <E> ReceiveChannel<E>. Returns index of the first element matching the given predicate, or -1 if the channel does not contain such element. |
|
suspend fun <E> ReceiveChannel<E>. Returns index of the last element matching the given predicate, or -1 if the channel does not contain such element. |
|
suspend fun <E> ReceiveChannel<E>. Returns the last element. suspend fun <E> ReceiveChannel<E>. Returns the last element matching the given predicate. |
|
suspend fun <E> ReceiveChannel<E>. Returns last index of element, or -1 if the channel does not contain element. |
|
suspend fun <E> ReceiveChannel<E>. Returns the last element, or suspend fun <E> ReceiveChannel<E>. Returns the last element matching the given predicate, or |
|
fun <E, R> ReceiveChannel<E>. Returns a channel containing the results of applying the given transform function to each element in the original channel. |
|
fun <E, R> ReceiveChannel<E>. Returns a channel containing the results of applying the given transform function to each element and its index in the original channel. |
|
fun <E, R : Any> ReceiveChannel<E>. Returns a channel containing only the non-null results of applying the given transform function to each element and its index in the original channel. |
|
suspend fun <E, R : Any, C : MutableCollection<in R>> ReceiveChannel<E>. Applies the given transform function to each element and its index in the original channel and appends only the non-null results to the given destination. |
|
suspend fun <E, R, C : MutableCollection<in R>> ReceiveChannel<E>. Applies the given transform function to each element and its index in the original channel and appends the results to the given destination. |
|
fun <E, R : Any> ReceiveChannel<E>. Returns a channel containing only the non-null results of applying the given transform function to each element in the original channel. |
|
suspend fun <E, R : Any, C : MutableCollection<in R>> ReceiveChannel<E>. Applies the given transform function to each element in the original channel and appends only the non-null results to the given destination. |
|
suspend fun <E, R, C : MutableCollection<in R>> ReceiveChannel<E>. Applies the given transform function to each element of the original channel and appends the results to the given destination. |
|
suspend fun <E, R : Comparable<R>> ReceiveChannel<E>. Returns the first element yielding the largest value of the given function or |
|
suspend fun <E> ReceiveChannel<E>. Returns the first element having the largest value according to the provided comparator or |
|
suspend fun <E, R : Comparable<R>> ReceiveChannel<E>. Returns the first element yielding the smallest value of the given function or |
|
suspend fun <E> ReceiveChannel<E>. Returns the first element having the smallest value according to the provided comparator or |
|
suspend fun <E> ReceiveChannel<E>. Returns suspend fun <E> ReceiveChannel<E>. Returns |
|
fun <E : Any> ReceiveChannel<E>.onReceiveOrNull(): SelectClause1<E?> Clause for select expression of receiveOrNull suspending function that selects with the element that
is received from the channel or selects with |
|
Splits the original channel into pair of lists,
where first list contains elements for which predicate yielded |
|
fun <T> ReceiveChannel<T>.receiveAsFlow(): Flow<T> 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. |
|
suspend fun <E : Any> ReceiveChannel<E>.receiveOrNull(): E? Retrieves and removes the element from this channel suspending the caller while this channel isEmpty
or returns |
|
Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element. |
|
Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element with its index in the original channel. |
|
fun <E : Any> ReceiveChannel<E?>. Returns an original collection containing all the non- |
|
suspend fun <E> ReceiveChannel<E>. Returns the single element, or throws an exception if the channel is empty or has more than one element. suspend fun <E> ReceiveChannel<E>. Returns the single element matching the given predicate, or throws exception if there is no or more than one matching element. |
|
suspend fun <E> ReceiveChannel<E>. Returns single element, or suspend fun <E> ReceiveChannel<E>. Returns the single element matching the given predicate, or |
|
suspend fun <E> ReceiveChannel<E>. Returns the sum of all values produced by selector function applied to each element in the channel. |
|
suspend fun <E> ReceiveChannel<E>. Returns the sum of all values produced by selector function applied to each element in the channel. |
|
fun <E> ReceiveChannel<E>. Returns a channel containing first n elements. |
|
fun <E> ReceiveChannel<E>. Returns a channel containing first elements satisfying the given predicate. |
|
suspend fun <E, C : SendChannel<E>> ReceiveChannel<E>. Send each element of the original channel and appends the results to the given destination. |
|
suspend fun <E, C : MutableCollection<in E>> ReceiveChannel<E>. Appends all elements to the given destination collection. |
|
suspend fun <E> ReceiveChannel<E>.toList(): List<E> Returns a List containing all elements. |
|
Returns a Map filled with all elements of this channel. suspend fun <K, V, M : MutableMap<in K, in V>> ReceiveChannel<Pair<K, V>>. Returns a MutableMap filled with all elements of this channel. |
|
suspend fun <E> ReceiveChannel<E>. Returns a MutableList filled with all elements of this channel. |
|
suspend fun <E> ReceiveChannel<E>. Returns a mutable set containing all distinct elements from the given channel. |
|
suspend fun <E> ReceiveChannel<E>. Returns a Set of all elements. |
|
fun <E> ReceiveChannel<E>. Returns a channel of IndexedValue for each element of the original channel. |
|
infix fun <E, R> ReceiveChannel<E>. Returns a channel of pairs built from elements of both channels with same indexes. Resulting channel has length of shortest input channel. fun <E, R, V> ReceiveChannel<E>. Returns a channel of values built from elements of both collections with same indexes using provided transform. Resulting channel has length of shortest input channels. |
Inheritors
interface ActorScope<E> : CoroutineScope, ReceiveChannel<E> Scope for actor coroutine builder. |
|
interface Channel<E> : SendChannel<E>, ReceiveChannel<E> Channel is a non-blocking primitive for communication between a sender (via SendChannel) and a receiver (via ReceiveChannel). Conceptually, a channel is similar to Java’s BlockingQueue, but it has suspending operations instead of blocking ones and can be closed. |