consume

inline fun <E, R> BroadcastChannel<E>.consume(
    block: ReceiveChannel<E>.() -> R
): R

Opens subscription to this BroadcastChannel and makes sure that the given block consumes all elements from it by always invoking cancel after the execution of the block.

inline fun <E, R> ReceiveChannel<E>.consume(
    block: ReceiveChannel<E>.() -> R
): R

Makes sure that the given block consumes all elements from the given channel by always invoking cancel after the execution of the block.

WARNING: It is planned that in the future a second invocation of this method on an channel that is already being consumed is going to fail fast, that is immediately throw an IllegalStateException. See this issue for details.

The operation is terminal.