Skip to content

Instantly share code, notes, and snippets.

@Sottti
Created October 10, 2025 22:25
Show Gist options
  • Save Sottti/04e5db79381168345b1c2d952885c4e7 to your computer and use it in GitHub Desktop.
Save Sottti/04e5db79381168345b1c2d952885c4e7 to your computer and use it in GitHub Desktop.
context(viewModel: ViewModel)
public fun <T> Flow<T>.stateInWhileSubscribed(
initialValue: T,
): StateFlow<T> = stateIn(
scope = viewModel.viewModelScope,
started = WhileSubscribed(stopTimeoutMillis = 5_000),
initialValue = initialValue,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment