ChannelReceiverContext

Simple wrapper around a channel that provides a context for receiving items in a more flexible manner.

Example usage:

val channel = Channel<Int>()
val context = ChannelReceiverContext(channel)

// Receive a single item
val item = context.next()

// Receive multiple items
val items = context.next(5)

// Receive multiple items with a timeout
val itemsWithTimeout = context.next(5, Duration.seconds(10))

// Mark the context as completed
context.markAsCompleted()

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract fun markAsCompleted()

Marks the receiver context as completed. After this method is called, no more items can be received from the channel.

Link copied to clipboard
abstract suspend fun next(): E

Awaits for the next item from the channel.

abstract suspend fun next(n: Int): List<E>

Awaits for the next N items from the channel. This method will suspend indefinitely until N items are received.

open suspend fun next(timeout: Duration): E?

Awaits for the next item from the channel, or null if the timeout is reached.

abstract suspend fun next(n: Int, timeout: Duration): List<E>

Awaits for the next N items from the channel, or until the timeout is reached. Once the timeout is reached, the list of received items is returned, even if fewer than N items have been received.