Skip to content

Instantly share code, notes, and snippets.

@JoseAlcerreca
Last active May 17, 2021 14:17
Show Gist options
  • Save JoseAlcerreca/0cc3eb08825924b10e336ceb4b11133b to your computer and use it in GitHub Desktop.
Save JoseAlcerreca/0cc3eb08825924b10e336ceb4b11133b to your computer and use it in GitHub Desktop.
class MyViewModel(...) : ViewModel() {
val result: StateFlow<Result<UiState>> = flow {
emit(repository.fetchItem())
}.stateIn(
scope = viewModelScope,
started = WhileSubscribed(5000), // Or Lazily because it's a one-shot
initialValue = Result.Loading
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment