CompletableFuture.stopIf

Pavel Rappo pavel.rappo at oracle.com
Fri Sep 2 09:10:27 UTC 2016


Hi Federico,

The right place to discuss this would be the Concurrency-interest mailing list:

	http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest

Thanks.

> On 2 Sep 2016, at 09:53, federico.fissore at gmail.com wrote:
> 
> Hi all
> 
> I hope this is the right place, since it's the first time I try to humbly contribute to jdk development
> 
> Is there still time to add a method to CompletableFuture?
> 
> I would like to have a stopIf/interruptIf method that stops a chain of CFs when the given predicate is true
> 
> Consider the following example:
> 
> fetchUser(id)
> - changeEmail(user)
> - notifyOtherSystems(user)
> 
> If fetchUser returns null (non existent ID), the following steps are non sense. At the moment, you have to copy/paste a check for a null user in both changeEmail and notifyOtherSystems steps.
> 
> What about:
> 
> fetchUser(id)
> - stopIf((user) -> user == null)
> - changeEmail(user)
> - notifyOtherSystemsOfNewEmail(user)
> 
> stopIf exceptionally completes the CF with a CompletionException.
> 
> Please note that fetchUser cannot complete exceptionally on its own, since it may be used elsewhere in the code base, where a null result has different semantics
> 
> Best regards
> 
> Federico Fissore



More information about the jdk9-dev mailing list