I have read the Scala Future and Promise and this post in stackoverflow, I understand the concept is that
You can think of futures and promises as two different sides of a pipe. On the promise side, data is pushed in, and on the future side, data can be pulled out.
Right now I am wondering how to do the same thing using Java 8's CompletableFuture
.
Example code:
Promise<String> promise = new Promise.DefaultPromise<>();
listOfString.stream().forEach(oneString -> {
promise.trySuccess(oneString);
});
//..... some other computation here ....
promise.future().map(new Mapfunction{...});
I am wondering how to use Java 8 CompletableFuture
to achieve the same, because I think CompletableFuture
does not really have data push in and data push out concept like Scala promise does.