Skip to content

Instantly share code, notes, and snippets.

@brh
Created January 26, 2022 14:05
Show Gist options
  • Save brh/24185e7ca0cee34e53ce7aab42129dd2 to your computer and use it in GitHub Desktop.
Save brh/24185e7ca0cee34e53ce7aab42129dd2 to your computer and use it in GitHub Desktop.
Pokemon multi call
override suspend fun getPokemonList(offset: Int): PokemonPageResponse {
val listResult = api.getPokemonList(offset)
val uiList = listResult.results.map { item ->
val id = item.url.extractIdFromUrl()
val deferred: Deferred<PokemonDetailUI> = repoScope.async(start = CoroutineStart.LAZY) {
val result = api.getPokemonDetails(id)
PokemonDetailUI(result.sprites.frontDefault, emptyList(), PokemonType("f"))
}
PokemonUI(item.name, id, deferred)
}
return PokemonPageResponse(
listResult.next?.getOffset(),
listResult.previous?.getOffset(),
uiList
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment