Flow Constraints
1.Context Preservation
Flow encapsulates its own execution context and never propagates or leaks it
downstream
2.Exception Transparency
Flow implementations never catch or handle exceptions that occur in
downstream flows
Channels
Channel is a non-blocking primitive for communication between two or more coroutines
using a sender (via SendChannel) and a receiver (via ReceiveChannel).
Provide a way to transfer a stream of values while Deferred Values are used to transfer
a single value between coroutines.
similar to Java's BlockingQueue, but has suspending operations instead of blocking
ones and can be closed.
SharedFlow
1.SharedFlow
2.StateFlow: Customized SharedFlow to hold latest value
Uses Lock to
manage thread
safety
NEVER
COMPLETES
StateFlow
1.Conflation – Drop Oldest: onBufferOverflow = BufferOverflow.DROP_OLDEST
2.distinctUntilChanged()
3.Replay Cache = 1: replay = 1
4.Value property: Holds the current state
It’s a SharedFlow with the following properties:
Practice :)
1.What’s the differences between Cold Flows and Hot Flows?
2.What’s the differences between Channels and SharedFlows?
3.What is the time complexity of emit function in SharedFlow ?
4.Are Coroutine Channels hot or cold?
5.What is the Logical structure of the buffer in SharedFlow?