[concurrency-interest] CompletionStage.handle() with function returning CompletionStage

Doug Lea dl at cs.oswego.edu
Sun Feb 21 15:54:03 EST 2016


On 02/12/2016 03:36 AM, Petter Måhlén wrote:
> Hi,
>
> One thing that I and my colleagues have felt is missing in CompletionStage is a
> version of handle() (and exceptionally()) taking a function that returns a
> CompletionStage<U> (or T) instead of a plain U. This is particularly useful when
> doing things like fallbacks or retries for remote service calls.

> We've implemented those methods ourselves, calling them 'handleCompose' and
> 'exceptionallyCompose':
> https://github.com/spotify/futures-extra/blob/master/src/main/java/com/spotify/futures/CompletableFuturesExtra.java#L110,
> but of course using a static method like that reads less well than the normal
> fluent API.
>
> What is the rationale for not including those versions?
>

I can see how this would be useful in some styles of programming using
CompletionStages. But when coming up with the APIs, no one predicted
this style might become common, so no one made a case for including it
in the main CompletionStage interface.

I was thinking that by letting this post sit a while, others might
try to make this case. But not yet.

-Doug





More information about the Concurrency-interest mailing list