0
0
Kotlinprogramming~5 mins

SharedFlow for event broadcasting in Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ACold flow
BSingle emission flow
CState holder
DHot flow
Which parameter controls how many past events SharedFlow replays to new subscribers?
Acapacity
BbufferSize
Creplay
Dtimeout
Which function is used to send an event to a SharedFlow?
Aemit()
Blaunch()
Csubscribe()
Dcollect()
What happens if no subscribers are collecting a SharedFlow when an event is emitted?
AEvent is lost
BEvent is buffered if replay > 0
CFlow stops
DException is thrown
Which of these is NOT a typical use case for SharedFlow?
AHolding the latest state value
BBroadcasting UI events
CSending one-time notifications
DSharing events between multiple collectors
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.