Featured image of post Flow Notes

Flow Notes

This post is my companion sketch notes for all the resources I consumed on the topic of flows. It is not meant to replace the info that I found on the internet but rather supplement it. Nor is it complete or should it be a standalone guide. In fact you can find an excellent list of my favourite resources at the end of the article. It is a document that helps me make sense of the topic. With that disclaimer out of the way…

Let’s take a step back and look at the suspend function. If your coroutine knowledge is rusty, freshen that up first.

Coroutines suspend

What if we want to provide multiple values? A stream of values that can be observed? Enter flows. At their most basic, flows have a producer and a consumer.

Producers and Consumers

The interface looks like this (spoiler it’s just suspend functions under the hood)

Flow Interface: Roman says no magic only suspend functions

The consumer gets the multiple values by using a terminal operator.

Terminal operators

If I need to change the produced values along the way before consuming them, there are transform operators.

Transform operators

How do I switch from main to io context?

Context preserve

What’s with the hot and cold flows? How do I remember which is which?

Hot and Cold flows

Some practical hot flows.

state and shared flows

Flows on Android

flows on Android

References

Kotlin Coroutines Flow in a nutshell

Kotlin Flows ~ an Android cheat sheet

Kotlin Flows in Android summary

Android flow

Asynchronous Flow | Kotlin

Flow under the hood: how does it really work

KotlinConf 2019: Asynchronous Data Streams with Kotlin Flow by Roman Elizarov

Kotlin Flows in a Nutshell

FlowMarbles

Android StateFlow and SharedFlow

If you are reading this far I will reward you with an Android portait.

Android