ActorScope

@ObsoleteCoroutinesApi interface ActorScope<E> : 
    CoroutineScope,
    ReceiveChannel<E>
(source)

Platform and version requirements: JVM

Scope for actor coroutine builder.

Note: This API will become obsolete in future updates with introduction of complex actors. See issue #87.

Properties

channel

abstract val channel: Channel<E>

A reference to the mailbox channel that this coroutine receives messages from. 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 ReceiveChannel functions on this interface delegate to the channel instance returned by this function.

Inherited Properties

coroutineContext

abstract val coroutineContext: CoroutineContext

The context of this scope. Context is encapsulated by the scope and used for implementation of coroutine builders that are extensions on the scope. Accessing this property in general code is not recommended for any purposes except accessing the Job instance for advanced usages.

isClosedForReceive

abstract val isClosedForReceive: Boolean

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.

isEmpty

abstract val isEmpty: Boolean

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.

onReceive

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 receive (see close for details).

Inherited Functions

cancel

abstract fun cancel(
    cause: CancellationException? = null
): Unit

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.

iterator

abstract operator fun iterator(): ChannelIterator<E>

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.

poll

abstract fun poll(): E?

Retrieves and removes an element from this channel if its not empty, or returns null if the channel is empty or is is closed for receive without a cause. It throws the original close cause exception if the channel has failed.

receive

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

Extension Functions

actor

fun <E> CoroutineScope.actor(
    context: CoroutineContext = EmptyCoroutineContext,
    capacity: Int = 0,
    start: CoroutineStart = CoroutineStart.DEFAULT,
    onCompletion: CompletionHandler? = null,
    block: suspend ActorScope<E>.() -> Unit
): SendChannel<E>

Launches new coroutine that is receiving messages from its mailbox channel and returns a reference to its mailbox channel as a SendChannel. The resulting object can be used to send messages to this coroutine.

newCoroutineContext

expect fun CoroutineScope.newCoroutineContext(
    context: CoroutineContext
): CoroutineContext

Creates a context for the new coroutine. It installs Dispatchers.Default when no other dispatcher or ContinuationInterceptor is specified, and adds optional support for debugging facilities (when turned on).