Shared Flow and State Flow

In this series of articles , we are discussing about Kotlin flows and in this article we will discuss about State Flow and Shared Flow.
Shared Flow
shares emitted value to all collectors in a broadcast way
all collectors receives all emitted values
This flow is active regardless of active collectors
You can customize the SharedFlow behavior in the following ways:
replaylets you resend a number of previously-emitted values for new subscribers.onBufferOverflowlets you specify a policy for when the buffer is full of items to be sent. The default value isBufferOverflow.SUSPEND, which makes the caller suspend. Other options areDROP_LATESTorDROP_OLDEST.
Code gist can be found in https://gist.github.com/vprabhu/adf153e7f3cbe6f5c39a4efe2c5d3400
State Flows
emits a single updated value to its collectors
current value can be accessed using
valueproperty
update{...}
thread safe function to change the state
excepts a block of code and this code block result is updated to
valueproperty which turns to be the updated value and this valueis emitted to all collectors
Code gist can be found in https://gist.github.com/vprabhu/3473f8c69375ba6271b57d426fcfacfd
Please leave your comments to improve and discuss more
Happy and Enjoy coding


