ArrayBroadcastChannel
class ArrayBroadcastChannel<E> :
AbstractSendChannel<E>,
BroadcastChannel<E>
(source)Platform and version requirements: JVM
Broadcast channel with array buffer of a fixed capacity. Sender suspends only when buffer is full due to one of the receives being slow to consume and receiver suspends only when buffer is empty.
Note, that elements that are sent to the broadcast channel while there are no openSubscription subscribers are immediately lost.
This channel is created by BroadcastChannel(capacity)
factory function invocation.
This implementation uses lock to protect the buffer, which is held only during very short buffer-update operations. The lock at each subscription is also used to manage concurrent attempts to receive from the same subscriber. The lists of suspended senders or receivers are lock-free.
Constructors
ArrayBroadcastChannel(capacity: Int) Broadcast channel with array buffer of a fixed capacity. Sender suspends only when buffer is full due to one of the receives being slow to consume and receiver suspends only when buffer is empty. |
Properties
val bufferDebugString: String |
|
val capacity: Int Buffer capacity. |
Inherited Properties
val isClosedForSend: Boolean Returns |
|
val isFull: Boolean Returns |
|
val onSend: SelectClause2<E, SendChannel<E>> Clause for select expression of send suspending function that selects when the element that is specified as parameter is sent to the channel. When the clause is selected the reference to this channel is passed into the corresponding block. |
Functions
Closes this channel with an optional exceptional cause.
This is an idempotent operation – repeated invocations of this function have no effect and return |
|
fun openSubscription(): SubscriptionReceiveChannel<E> Subscribes to this BroadcastChannel and returns a channel to receive elements from it. The resulting channel shall be closed to unsubscribe from this broadcast channel. |
Inherited Functions
Invoked after successful close. |
|
Adds element into this queue if it is possible to do so immediately without violating capacity restrictions
and returns |
|
Adds element into to this channel, suspending the caller while this channel isFull, or throws exception if the channel isClosedForSend (see close for details). |
|
open fun toString(): String |
Extension Functions
fun <E, R> BroadcastChannel<E>.consume( 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. |
|
suspend fun <E> BroadcastChannel<E>.consumeEach( Subscribes to this BroadcastChannel and performs the specified action for each received element. |
|
fun <E> SendChannel<E>.sendBlocking(element: E): Unit Adds element into to this channel, blocking the caller while this channel Channel.isFull, or throws exception if the channel Channel.isClosedForSend (see Channel.close for details). |