June 2018
Intermediate to advanced
310 pages
6h 32m
English
In Chapter 7, Staying Reactive, which was dedicated to reactive programming, we discussed Observable and subject that were producing streams of values. Much in the same way, Kotlin provides us with the produce() function.
This function creates coroutine is backed up by ReceiveChannel<T>, where T is the type the coroutine produces:
val publisher: ReceiveChannel<Int> = produce { for (i in 2018 downTo 1970) { // Years back to Unix send(i) delay(20) }}
In Rx there's the onNext() method that we covered in Chapter 7, Staying Reactive.
Producers have a send() function, which is very similar.
Much like the Rx Observable that provided the subscribe() method, this channel, has the consumeEach() function:
publisher.consumeEach { println
Read now
Unlock full access