Skip to content

Instantly share code, notes, and snippets.

@skydoves
Created September 20, 2024 13:21
Show Gist options
  • Save skydoves/c365fa25cad148eff5716190242a3ada to your computer and use it in GitHub Desktop.
Save skydoves/c365fa25cad148eff5716190242a3ada to your computer and use it in GitHub Desktop.
OnetimeWhileSubscribed_sample
val pokemon = savedStateHandle.getStateFlow<Pokemon?>("pokemon", null)
val pokemonInfo: StateFlow<PokemonInfo?> =
pokemon.filterNotNull().flatMapLatest { pokemon ->
detailsRepository.fetchPokemonInfo(pokemon.id)
}.stateIn(
scope = viewModelScope,
started = OnetimeWhileSubscribed(5_000),
initialValue = null,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment