CompletionStage:在异常块内返回CompletionStage

时间:2016-02-25 00:19:15

标签: java java-8 promise completable-future

如果发生异常,有没有办法返回新的CompletionStage

exceptionally的API,似乎不允许您这样做。有办法解决这个问题吗?

基本上我想为flatMap案例thenComposeexceptionally)做

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());

}

0 个答案:

没有答案