Taking a group of elements

You can also read values using take(), sending the amount of elements to take as a parameter. For example, you can consume the first three elements from a producer like this:

producer.take(3).consumeEach {
println(it)
}

Notice that take() on a ReceiveChannel<E> will return a ReceiveChannel<E> too, and because take() is an intermediate operation, the actual value of those three elements will be calculated when a terminal operation happens – in this case the terminal operation will be consumeEach().

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.135.225