consumeEach

@ObsoleteCoroutinesApi inline suspend fun <E> BroadcastChannel<E>.consumeEach(
    action: (E) -> Unit
): Unit
(source)

Subscribes to this BroadcastChannel and performs the specified action for each received element.

Note: This API will become obsolete in future updates with introduction of lazy asynchronous streams. See issue #254.

@ExperimentalCoroutinesApi inline suspend fun <E> ReceiveChannel<E>.consumeEach(
    action: (E) -> Unit
): Unit
(source)

Performs the given action for each received element and cancels the channel after the execution of the block. If you need to iterate over the channel without consuming it, a regular for loop should be used instead.

The operation is terminal. This function consumes all elements of the original ReceiveChannel.