Recall & Review
beginner
What is SharedFlow in Kotlin?
SharedFlow is a hot flow that allows multiple subscribers to receive the same emitted values, useful for broadcasting events to many collectors.
Click to reveal answer
intermediate
How does SharedFlow differ from
StateFlow?SharedFlow does not hold a current value and is used for events, while StateFlow always holds the latest value and is used for state updates.
Click to reveal answer
intermediate
What does the
replay parameter in SharedFlow control?The replay parameter controls how many past emitted values are buffered and replayed to new subscribers when they start collecting.
Click to reveal answer
beginner
Why is SharedFlow considered a hot flow?
Because it emits values regardless of whether there are active subscribers, unlike cold flows which start emitting only when collected.
Click to reveal answer
beginner
How do you emit an event to a SharedFlow?
You use the
emit() or tryEmit() functions on the MutableSharedFlow instance to send events to all subscribers.Click to reveal answer
What type of flow is SharedFlow in Kotlin?
✗ Incorrect
SharedFlow is a hot flow that emits values regardless of active subscribers.
Which parameter controls how many past events SharedFlow replays to new subscribers?
✗ Incorrect
The replay parameter sets how many past events are replayed to new subscribers.
Which function is used to send an event to a SharedFlow?
✗ Incorrect
emit() is used to send events to a SharedFlow.
What happens if no subscribers are collecting a SharedFlow when an event is emitted?
✗ Incorrect
Events are buffered up to the replay count and delivered to future subscribers.
Which of these is NOT a typical use case for SharedFlow?
✗ Incorrect
Holding the latest state value is the role of StateFlow, not SharedFlow.
Explain how SharedFlow helps in broadcasting events to multiple subscribers in Kotlin.
Think about how events are sent and received by many listeners at once.
You got /4 concepts.
Describe the difference between SharedFlow and StateFlow and when you would use each.
Consider if you want to hold a value or just send events.
You got /4 concepts.