Last active
May 17, 2021 14:17
-
-
Save JoseAlcerreca/0cc3eb08825924b10e336ceb4b11133b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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