logo
logo
Sign in

7 useful ways to create Flow in Kotlin

avatar
Canopas
7 useful ways to create Flow in Kotlin

In this blog post we are going to learn different ways to create Kotlin Flow with examples.


7 very important and useful ways to create Flow in Kotlin with examples.


  1. flowOf()
  2. asFlow()
  3. flow{}
  4. MutableStateFlow & MutableSharedFlow()
  5. ChannelFlow
  6. CallbackFlow
  7. emptyFlow


Creates an instance of cold flow from the given suspendable block where we can manually emit values.


It defines the corresponding constructor functions to create a hot flow that can be directly updated.


Creates an instance of cold flow with the elements that are sent to a SendChannel.


ChannelFlow produces the values in a separate coroutine without waiting for a receiver to complete processing on emitted items. 


Here, the producer emits the next item only after the previous item is processed by the consumer.


Here, the producer does not wait for its receiver, its works independently from its consumer.


Read full version of this blog post with source code on our canopas blog.

collect
0
avatar
Canopas
guide
Zupyak is the world’s largest content marketing community, with over 400 000 members and 3 million articles. Explore and get your content discovered.
Read more