rrva
03/11/2020, 9:50 PMbdawg.io
03/11/2020, 10:03 PMlistOf(Foo("timeout"))
You need to allow exceptions to be thrown (including CancellationException
) if you want those to work properly. You also don't get any benefit by attaching a blank job in your CoroutineScope(Job() + <http://Dispatchers.IO|Dispatchers.IO> + MDCContext())
scopebdawg.io
03/11/2020, 10:06 PMfun fetchFooAsync(ids:List<String>): CompletableFuture<List<Foo>> {
return GlobalScope.async(<http://Dispatchers.IO|Dispatchers.IO> + MDCContext()) {
try {
client.fetchFoo(ids)
} catch (e: CancellationException) {
throw e // you must propogate cancellation
} catch (e: Throwable) {
println(e.message)
throw e // you must propogate an exception if you want CompletableFuture to know about it
}
}.asCompletableFuture()
}
rrva
03/11/2020, 10:35 PMrrva
03/11/2020, 10:44 PMrrva
03/11/2020, 11:00 PM