8.48M
Category: informaticsinformatics

Kotlin flow

1.

KOTLIN
FLOW
API
Dennis Petuhov

2.

1 What is Flow?
2 Why do we need Flow?
3 Working of Flow: Entities involved in
Flow
4 Types of Flow
5 Commonly used operators and their
types
6 Flow Builders
7 Exception Handling in Flow
8 Comparison of LiveData and Flow
9 StateFlow and SharedFlow
10 stateIn and shareIn
11 Collecting Flow in Compose
1

3.

What is Flow?
• A stream of data that can be computed asynchronously is conceptually referred to as a Flow.
• It is constructed using Coroutines. An appropriate Kotlin type for modeling data streams is Flow.
• Flow, like LiveData and RxJava streams, allows you to implement the observer pattern: a software design pattern
consisting of an object (source) that keeps a list of its dependents, called observers (collectors) and automatically
notifies them of any state changes.
• A Flow uses suspended functions to consume and produce in an asynchronous manner.
2

4.

Why do we need Flow?
◦ After Coroutines were introduced, people started enjoying them due to their simplicity and structured concurrency.
◦ Coroutines, combined with the growing usage of Kotlin, led people to express their interest in having a pure Kotlin
implementation of RxJava to leverage the power of Kotlin like Type Systems, Coroutines, etc. When these are
combined, they form Flow.
◦ We can say Flow takes advantage of LiveData and RxJava.
◦ However, Kotlin Flow stands out as a game changer. This feature from the Kotlin Coroutines library provides an
easier and more intuitive way to handle asynchronous streams of data.
3

5.

4

6.

Working of Flow: Entities involved in
Flow
5

7.

Upstream and Downstream
6

8.

Flow Builders
7

9.

8

10.

Commonly used operators and their
types
9

11.

10

12.

Intermediate Operators
11

13.

Types of Flow
12

14.

Exception Handling in Flow
13

15.

14

16.

StateFlow and SharedFlow
15

17.

stateIn and shareIn
16

18.

Collecting Flow in Compose
17

19.

Thank
You!
18
English     Русский Rules