I have certain flow that runs async using the CompletableFuture
, e.g.:
foo(...)
.thenAccept(aaa -> {
if (aaa == null) {
break!
}
else {
...
}
})
.thenApply(aaa -> {
...
})
.thenApply(...
So if my foo()
returns null
(in a future) I need to break very soon, otherwise, the flow continue.
For now I have to check for null
all the way, in every future block; but that is ugly.
Would this be possible with CompletableFuture
?
EDIT
With CompletableFuture
you can define your flow of async tasks, that are executed one after the other. For example, you may say:
Do A, and when A finishes, do B, and then do C...
My question is about breaking this flow and saying:
Do A, but if result is null break; otherwise do B, and then do C...
This is what I meant by 'breaking the flow`.