stateInWhileSubscribed

context(viewModel: ViewModel)
fun <T> Flow<T>.stateInWhileSubscribed(initialValue: T, stopTimeout: Duration = 5.seconds): StateFlow<T>(source)

Extension for converting a Flow to a StateFlow in a ViewModel context.

Parameters

initialValue

the initial value of the state flow

stopTimeout

configures a delay between the disappearance of the last subscriber and the stopping of the sharing coroutine.