如果发生异常,有没有办法返回新的CompletionStage
?
exceptionally
的API,似乎不允许您这样做。有办法解决这个问题吗?
基本上我想为flatMap
案例thenCompose
(exceptionally
)做
public CompletionStage<String> cleanupTask() {
//DO something long running
}
public CompletionStage<String> workThatCanFail() {
//Some long running task that may fail
}
public void action() {
CompletionStage<String> work =
workThatCanFail()
.exceptionally(throwable -> cleanupTask());
}