xii
02/03/2022, 8:33 AMJoffrey
02/03/2022, 9:19 AMCompletableFuture
- the Java one? Is your client exposing suspend functions to the service layer?async
xii
02/03/2022, 9:23 AMJoffrey
02/03/2022, 9:24 AMclass Client {
suspend fun fetchThing1(): TransformedThing1 {
val rawValue1 = doTheAsyncThing1().await()
return transformSomehow(rawValue1)
}
suspend fun fetchThing2(): TransformedThing2 {
val rawValue2 = doTheAsyncThing2().await()
return transformSomehow(rawValue2)
}
}
class Service(val client: Client) {
suspend fun doStuffWithBoth(): CombinedThing = coroutineScope {
// making both calls concurrently
val thing1 = async { client.fetchThing1() }
val thing1 = async { client.fetchThing2() }
combineBothResultsIntoASingleThing(thing1.await(), thing2.await())
}
}
xii
02/11/2022, 4:16 PM