CompletableFuture (original) (raw)
Doug Lea dl at cs.oswego.edu
Wed Nov 28 09:03:42 PST 2012
- Previous message: CompletableFuture
- Next message: CompletableFuture
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 11/28/12 11:09, Remi Forax wrote:
The void completion methods don't return new CompletableFuture (no need) but just "return this" to be nice to fluency fans. aaaaaah, It means that with CompletableFuture c = completableFuture.then(e -> foo(e)); c.isDone() can be true even if foo() has still not finished. Having a fluent interface is a nice trick but here, the resulting semantics is too weird IMO.
Thanks. Good point. I initially defined these as void (as opposed to the Function ones, that return a new one to maintain value). Changing to "return this" makes them much simpler to use but as you point out makes it look like the "." in a compound expression refers to the wrong thing. I guess the best way out is to actually create/return a little CompletableFuture here, which doesn't appreciably inflate cost and precludes misinterpretation. So...
/**
* Creates and returns a CompletableFuture> that is completed
* after performing the given action with the result of this
* CompletableFuture if/when it completes normally.
*
* @return the new CompletableFuture
*/
public CompletableFuture<Void> then(Block<? super T> action);
And similarly for and(), or(), exceptionally(). We still have the function vs action method overriding issue though.
-Doug
- Previous message: CompletableFuture
- Next message: CompletableFuture
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the lambda-libs-spec-observers mailing list