ChannelWithCloseableData

class ChannelWithCloseableData<T>(capacity: Int = RENDEZVOUS, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND) : ReceiveChannel<ChannelWithCloseableData.CloseableData<T>> (source)

A channel that sends and receives data along with a close action to be executed when the data is no longer needed.

Parameters

T

The type of data to be sent and received.

capacity

The capacity of the channel.

onBufferOverflow

The behavior when the buffer overflows.

Constructors

Link copied to clipboard
constructor(capacity: Int = RENDEZVOUS, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND)

Types

Link copied to clipboard
class CloseableData<T>(val data: T, val onClose: () -> Unit) : Closeable

Properties

Link copied to clipboard
@DelicateCoroutinesApi
open override val isClosedForReceive: Boolean
Link copied to clipboard
@ExperimentalCoroutinesApi
open override val isEmpty: Boolean
Link copied to clipboard
open override val onReceive: SelectClause1<ChannelWithCloseableData.CloseableData<T>>
Link copied to clipboard
open override val onReceiveCatching: SelectClause1<ChannelResult<ChannelWithCloseableData.CloseableData<T>>>
Link copied to clipboard

Functions

Link copied to clipboard
open override fun cancel(cause: CancellationException?)
Link copied to clipboard
open operator override fun iterator(): ChannelIterator<ChannelWithCloseableData.CloseableData<T>>
Link copied to clipboard
Link copied to clipboard
open suspend override fun receive(): ChannelWithCloseableData.CloseableData<T>

Receives data along with its close action from the channel.

Link copied to clipboard
open suspend override fun receiveCatching(): ChannelResult<ChannelWithCloseableData.CloseableData<T>>
Link copied to clipboard
Link copied to clipboard
suspend fun send(data: T, onClose: () -> Unit = {})

Sends data along with a close action to the channel.

Link copied to clipboard
open override fun tryReceive(): ChannelResult<ChannelWithCloseableData.CloseableData<T>>
Link copied to clipboard
inline suspend fun <T> ChannelWithCloseableData<T>.useConsumeEach(action: (T) -> Unit)
Link copied to clipboard
inline suspend fun <T, R> ChannelWithCloseableData<T>.useReceive(block: (T) -> R): R

Receives data from the channel and uses it in a block, ensuring that the data is properly closed after use.