Setting Up a Flow

Flows are Kotlin’s way to represent asynchronous streams of data. At a high level, flows support two actions: emitting and collecting. When you collect a flow, you are registering a listener that will receive all the items that get emitted from the flow. A flow can emit any number of items over its lifetime – or it might not emit any items at all.

The specifics of how emission and collection work depend on how the flow is created. Sometimes you will be able to directly manipulate the flow and ask it to emit a specific value. Other times, you will not have any access to the emitting functionality and will only be able to collect from the flow.

In this chapter, you will see examples of two kinds of flows that behave ...

Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.