federico.fissore at federico.fissore at
Fri Sep 2 08:53:25 UTC 2016

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:

  - 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:

  - 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