I would like to fully understand what happens here.
sharedFlow.debounce(250)
.onEach(::updateGroupingStrategy)
.shareIn(viewModelScope, SharingStarted.WhileSubscribed(5000L), replay = 1)
debounce
Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout. The latest value is always emitted.
+
debounce helps to detect the state when no new data is submitted for some time, effectively allowing you to process a data when the input is completed.
From my perspective, I delay subscribing sharedflow
for 250L
ms or I only subscribe values every and after 250L
?
onEach
* Returns a flow that invokes the given [action] **before** each value of the upstream flow is emitted downstream.
From my perspective, quite don't understand it. First return flow then start subscribing, assign value for it?
.shareIn
Sharing is started when the first subscriber appears, immediately stops when the last subscriber disappears (by default), keeping the replay cache forever (by default).
It has the following optional parameters:
stopTimeoutMillis — configures a delay (in milliseconds) between the disappearance of the last subscriber and the stopping of the sharing coroutine. It defaults to zero (stop immediately).
replay - the number of values replayed to new subscribers (cannot be negative, defaults to zero).
From my perspective, after there is not more subscriber I wait 5000L
miliseconds then I make action? Replay I do not understand.