Skip to content

Instantly share code, notes, and snippets.

@Kashif-E
Last active March 5, 2022 15:35
Show Gist options
  • Save Kashif-E/b9bf78a88de761e2ce4a8fb2573c239f to your computer and use it in GitHub Desktop.
Save Kashif-E/b9bf78a88de761e2ce4a8fb2573c239f to your computer and use it in GitHub Desktop.
Parallel API calls With HOF part 3
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