Charlie Christensen
11/23/2020, 3:32 PMval viewState: Flow<iewState> = viewState()
.shareIn(viewModelScope, SharingStarted.Eagerly, 1)
.onSubscription {
optionallyTriggerActionAfterDelay()
}
private suspend fun optionallyTriggerActionAfterDelay() {
if (valueIsTrue) {
delay(5000)
triggerAction()
}
}
This suspends the flow and delays the initial emission until the delay is complete.
I’ve tried launching another coroutine in the same scope but it still seems to block
private suspend fun optionallyTriggerActionAfterDelay() = coroutineScope {
launch {
if (valueIsTrue) {
delay(5000)
triggerAction()
}
}
}
And just using a different scope but this doesnt cancel
viewModelScope.launch {
if (valueIsTrue) {
delay(5000)
triggerAction()
}
}
I could just create a separate variable that would still be tied to the view lifecycle but I am more just curious if something like this can/should be done?