Retry in Java futures (part 2)
This is a follow-up to Retry in Java futures. This post presented a snippet of code demonstrating how to compose futures in Java, specifically java.util.concurrent.CompletableFuture. It demonstrated how to swallow exceptions and compose futures including branching etc.
It turns out that I need to interoperate with Guava futures too, specifically com.google.common.util.concurrent.ListenableFuture. In some ways this post can be considered to be a short translation guide for switching back and forth between CompletableFuture and ListenableFuture.
On first encountering ListenableFuture I was dismayed that, unlike CompletableFuture, this interface does not expose any methods for composing futures. CompletableFuture, for example, provides the following and many more:
exceptionallythenComposethenApply
On deeper inspection, however, we find that Guava eschews interface methods for static helper methods on the com.google.common.util.concurrent.Futures class. Roughly corresponding to the methods mentioned above we find:
catchingAsynccorresponding toexceptionallytransformAsynccorresponding tothenComposetransformcorresponding tothenApply
Read full article from Retry in Java futures (part 2)
No comments:
Post a Comment