I've been working extensively with Google Guava and ListenableFutures as of late, and something I've been finding missing is a way to provide an out-of-order streaming handler of future completions. What I'm envisioning is an iterable which blocks on next() until another future returns.
Before I go through the effort of creating my own, does one exist already?
If not, my thought was to leverage the callback functionality of a ListenableFuture to push results onto a BlockingQueue. The goal is to process returned values as soon as they're back. Futures.successfulAsList()
is great, but waits for all values before returning rather than letting me schedule other useful work.
You can use java.util.concurrent.CompletionService
. Its method take
could be easily wrapped to Iterator.next()
if it didn't throw InterruptedException
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With