[concurrency-interest] CompletableFuture.stopIf

federico.fissore at gmail.com federico.fissore at gmail.com
Fri Sep 2 06:18:18 EDT 2016

Hi all

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, the following steps are nonsense. 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 Concurrency-interest mailing list