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()
Content copied to clipboard
Functions
Link copied to clipboard
Marks the receiver context as completed. After this method is called, no more items can be received from the channel.
Link copied to clipboard
Awaits for the next item from the channel.
Awaits for the next N items from the channel. This method will suspend indefinitely until N items are received.
Awaits for the next item from the channel, or null if the timeout is reached.
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.