Similar presentations:
Kotlin flow
1.
KOTLINFLOW
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.
46.
Working of Flow: Entities involved inFlow
5
7.
Upstream and Downstream6
8.
Flow Builders7
9.
810.
Commonly used operators and theirtypes
9
11.
1012.
Intermediate Operators11
13.
Types of Flow12
14.
Exception Handling in Flow13
15.
1416.
StateFlow and SharedFlow15
17.
stateIn and shareIn16
18.
Collecting Flow in Compose17
19.
ThankYou!
18