I've been playing with CompletionStage/CompletableFuture in Java 8 in order to do asynchronous processing, which works quite well. However, sometimes I want a stage to perform asynchronous processing of an iterator/stream of items, and there doesn't seem to be a way to do this.
Specifically, Stream.forEach() has the semantics that after the call all items have been processed. I would want the same thing, but with a CompletionStage instead, e.g.:
CompletionStage<Void> done = stream.forEach(...);
done.thenRun(...);
If the Stream is backed by an asynchronous streaming result this would be much better than waiting for it to be complete in the above code itself.
Is it possible to construct this with current Java 8 API somehow? Workarounds?