Last active
March 5, 2022 15:35
-
-
Save Kashif-E/b9bf78a88de761e2ce4a8fb2573c239f to your computer and use it in GitHub Desktop.
Parallel API calls With HOF part 3
This file contains 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 repository{ | |
fun getItems( result : (humans: List<Humans>, birds: List<Birds> , | |
reptiles: List<Reptiles> )-> Unit) { | |
try { | |
CoroutineScope(Dispatchers.IO).launch { | |
val humanResponse = async { | |
apiService.getHumans() | |
} | |
val reptileResponse = async { | |
apiServices.getReptiles() | |
} | |
val birdResponse = async { | |
apiServices.getBirds( | |
) | |
} | |
val humans = humanResponse.await() | |
val reptiles = reptileResponse.await() | |
val birds = birdResponse.await() | |
result(humans, reptiles , birds) | |
} | |
} catch (e: Exception) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment