๐ค Do you know the difference between an upstream and a downstream flow in Kotlin coroutines?
- Nikolay Miroshnychenko
- Feb 22, 2024
- 1 min read
If you go looking through flow documentation in coroutines, you will eventually run into something like this:
๐๐ฏ ๐ฑ๐ข๐ณ๐ต๐ช๐ค๐ถ๐ญ๐ข๐ณ, ๐ต๐ฉ๐ช๐ด ๐ฐ๐ฑ๐ฆ๐ณ๐ข๐ต๐ฐ๐ณ ๐ฆ๐ฏ๐ด๐ถ๐ณ๐ฆ๐ด ๐ต๐ฉ๐ข๐ต ๐ฅ๐ฐ๐ธ๐ฏ๐ด๐ต๐ณ๐ฆ๐ข๐ฎ ๐ง๐ญ๐ฐ๐ธ ๐ฅ๐ฐ๐ฆ๐ด ๐ฏ๐ฐ๐ต ๐ณ๐ฆ๐ด๐ถ๐ฎ๐ฆ ๐ฐ๐ฏ ๐ค๐ข๐ฏ๐ค๐ฆ๐ญ๐ญ๐ข๐ต๐ช๐ฐ๐ฏ ๐ฆ๐ท๐ฆ๐ฏ ๐ช๐ง ๐ต๐ฉ๐ฆ ๐ฆ๐ญ๐ฆ๐ฎ๐ฆ๐ฏ๐ต๐ธ๐ข๐ด ๐ข๐ญ๐ณ๐ฆ๐ข๐ฅ๐บ ๐ฆ๐ฎ๐ช๐ต๐ต๐ฆ๐ฅ ๐ฃ๐บ ๐ต๐ฉ๐ฆ ๐ถ๐ฑ๐ด๐ต๐ณ๐ฆ๐ข๐ฎ ๐ง๐ญ๐ฐ๐ธ.
You will see a reference to an "upstream" and a "downstream" flow everywhere in the docs.
It was challenging for me to understand what those definitions mean, so I put together an animation to help you understand as well.
โฌ๏ธ Upstream flow - When you apply an intermediate operator to a flow, you are affecting the part of the flow that comes before (or "upstream of") the operator.
โฌ๏ธ Downstream flow - Side of the flow that proceeds after applying an intermediate operator.
Hope my animation helps you clear up the confusion!
Comentarios