```/** * receive a chunk of elements from channel...
# announcements
p
Copy code
/**
 * receive a chunk of elements from channel.
 *
 * @param size maximum amount of elements to receive
 * @return list of elements (empty list indicates the channel is closed)
 */
@ExperimentalCoroutinesApi
suspend fun <E : Any> ReceiveChannel<E>.receiveChunk(size: Int): List<E> =
  mutableListOf<E>().apply {
    for (i in 0 until size) {
      receiveOrNull()?.apply(::add) ?: break
    }
  }