CompletionStage

Doug Lea dl at cs.oswego.edu
Sun Jun 30 13:34:08 PDT 2013


Thanks!

On 06/30/13 16:03, Sam Pullara wrote:
> I like the idea of the CompletionStage interface, it would be nice if
> CompletableFuture was an interface as well so we could theoretically swap out
> the implementation. Here are some comments on the API in general:

To preview what I'll write in c-i post:

Problem: Some people demand some CompletableFuture methods
be present, and some demand that the same ones be absent.

Solution: No one objects to the stage methods, so factor them out.
Now, you can create things like (to pick on cancel()):
   class MyCompletableFuture extends CompletableFuture { ...
     boolean cancel(...) { throw new UnsupportedOperationException(); }
   }
   class MyCompletionStage implements CompletionStage {
     MyCompletableFuture cf ...
     // delegate all methods to cf;
   }

And many variations like this in which you may choose to
have a (strictly internal) crippled/weird CF subclass, but
a perfectly fine and compliant CompletionStage implementation.
Design-by-UOE is an odd extension policy, but better than all
the others I know for this class.

>
> As I was converting a test I had written for my Promises, there seems to be a
> missing method. It appears that both handle() and exceptionally() force the
> Future to then succeed.

They can (re)throw any exception they like when completed exceptionally.
Which I think gives you the effects you wanted in next few parags of
your mail?

>
> I was also somewhat surprised to find that my RuntimeExceptions were being
> wrapped in CompletionException when they are passed to handle() and
> exceptionally().

Right. This is sometimes a little annoying but it is also
among the few conventions that mesh with Future method specs.
At least the spec tells you clearly that this happens.

> For cancellation, it doesn't look like there is any way to get the message
> downstream. In promises, cancellations go the opposite direction to exceptions
> which means you can react to them. In CompletionFuture it appears that they
> don't propagate down to the child CompletableFutures

Yes, they do (unless an intervening handle/exceptionally.)

-Doug



More information about the lambda-libs-spec-experts mailing list