How can I return the String "newURL" with coroutin...
# coroutines
l
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
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
Thanks