@ObsoleteCoroutinesApi interface ActorScope<E> : 

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.



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


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.


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, so that the receive attempt throws ClosedReceiveChannelException. If the channel was closed because of the exception, it is considered closed, too, but it is called a failed channel. All suspending attempts to receive an element from a failed channel throw the original close cause exception.


abstract val isEmpty: Boolean

Returns true if the channel is empty (contains no elements) and the receive attempt will suspend. This function returns false for isClosedForReceive channel.


abstract val onReceive: SelectClause1<E>

Clause for select expression of receive suspending function that selects with the element that is received from the channel. The select invocation fails with exception if the channel isClosedForReceive (see close for details).

Inherited Functions


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.


abstract operator fun iterator(): ChannelIterator<E>

Returns new iterator to receive elements from this channels using for loop. Iteration completes normally when the channel is isClosedForReceive without cause and throws the original close cause exception if the channel has failed.


abstract fun poll(): E?

Retrieves and removes the element from this channel, or returns null if this channel is empty or is isClosedForReceive without cause. It throws the original close cause exception if the channel has failed.


abstract suspend fun receive(): E

Retrieves and removes the element from this channel suspending the caller while this channel is empty, or throws ClosedReceiveChannelException if the channel isClosedForReceive. If the channel was closed because of the exception, it is called a failed channel and this function throws the original close cause exception.

Extension Functions


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


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

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