https://kotlinlang.org logo
#coroutines
Title
# coroutines
l

Lewon.G

10/21/2019, 12:39 PM
How can I return the String "newURL" with coroutines ? fun firstServerRequest(): String? { val service = pokemonNetwork.service service.getAllPokemonDatas(50,0).enqueue(object : Callback<PokemonList> { override fun onFailure(call: Call<PokemonList>, t: Throwable) { } override fun onResponse(call: Call<PokemonList>, response: Response<PokemonList>) { response.body()?.results?.forEach { pokemon -> var newURL = pokemon.url } } }) return newURL }
e

Evan R.

10/21/2019, 12:44 PM
You can wrap callback-based APIs in the
suspendCoroutine
block to use them in suspending functions as detailed here: https://stackoverflow.com/a/48562175
l

Lewon.G

10/21/2019, 12:57 PM
Thanks
3 Views