SendChannel

interface SendChannel<in E>(source)

Sender's interface to a Channel.

Combined, SendChannel and ReceiveChannel define the complete Channel interface.

It is not expected that this interface will be implemented directly. Instead, the existing Channel implementations can be used or delegated to.

Inheritors

Properties

Link copied to clipboard

Returns true if this channel was closed by an invocation of close or its receiving side was cancelled. This means that calling send will result in an exception.

Link copied to clipboard

Clause for the select expression of the send suspending function that selects when the element that is specified as the parameter is sent to the channel. When the clause is selected, the reference to this channel is passed into the corresponding block.

Functions

Link copied to clipboard
abstract fun close(cause: Throwable? = null): Boolean

Closes this channel so that subsequent attempts to send to it fail.

Link copied to clipboard
abstract fun invokeOnClose(handler: (cause: Throwable?) -> Unit)

Registers a handler that is synchronously invoked once the channel is closed or the receiving side of this channel is cancelled. Only one handler can be attached to a channel during its lifetime. The handler is invoked when isClosedForSend starts to return true. If the channel is closed already, the handler is invoked immediately.

Link copied to clipboard
abstract suspend fun send(element: E)

Sends the specified element to this channel.

Link copied to clipboard
abstract fun trySend(element: E): ChannelResult<Unit>

Attempts to add the specified element to this channel without waiting.

Link copied to clipboard

Adds element to this channel, blocking the caller while this channel is full, and returning either successful result when the element was added, or failed result representing closed channel with a corresponding exception.