Channels and flow

Channels are a newer feature in Kotlin that can transfer streams of values similar to how an Observable stream might work in RxJava. Using Channels, it's possible to create theoretically infinite streams of data and process that data asynchronously in an efficient manner. Consumers can then operate on the results of the asynchronous operations in much the same way that an Observable chain is subscribed to.

Flow is also a new feature in Kotlin, built on top of coroutines, and designed to enable cold asynchronous streams of data. This is similar to channels, and yet there is an important distinction. Flow will only emit values once something is listening for those values, and Flow doesn't necessarily solve any concurrency challenges. It's meant simply to provide asynchronous streams of data.

In this section, we've examined several different threading and concurrency concepts to better understand the tools that are available in the Kotlin ecosystem. You'll learn more about Coroutines, Channels, and Flow in Chapter 10, Practical Concurrency.