ProducerScope

interface ProducerScope<in E> : 
    CoroutineScope,
    SendChannel<E>
(source)

Platform and version requirements: JVM

Scope for produce coroutine builder.

Properties

channel

abstract val channel: SendChannel<E>

A reference to the channel that this coroutine sends elements to. It is provided for convenience, so that the code in the coroutine can refer to the channel as channel as apposed to this. All the SendChannel functions on this interface delegate to the channel instance returned by this function.

Inherited Properties

coroutineContext

open val coroutineContext: CoroutineContext

Returns the context of this coroutine.

isActive

abstract val isActive: Boolean

Returns true when this coroutine is still active (has not completed and was not cancelled yet).

isClosedForSend

abstract val isClosedForSend: Boolean

Returns true if this channel was closed by invocation of close and thus the send and offer attempts throws exception.

isFull

abstract val isFull: Boolean

Returns true if the channel is full (out of capacity) and the send attempt will suspend. This function returns false for isClosedForSend channel.

onSend

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

Inherited Functions

close

abstract fun close(cause: Throwable? = null): Boolean

Closes this channel with an optional exceptional cause. This is an idempotent operation – repeated invocations of this function have no effect and return false. Conceptually, its sends a special “close token” over this channel.

offer

abstract fun offer(element: E): Boolean

Adds element into this queue if it is possible to do so immediately without violating capacity restrictions and returns true. Otherwise, it returns false immediately or throws exception if the channel isClosedForSend (see close for details).

send

abstract suspend fun send(element: E): Unit

Adds element into to this channel, suspending the caller while this channel isFull, or throws exception if the channel isClosedForSend (see close for details).

Extension Functions

sendBlocking

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