相关疑难解决方法(0)

Java8 CompletableFuture recoverWith等价?例如异常但返回CompletableFuture <U>

我没有看到使用异步结果处理异常的明显方法.例如,如果我想重试异步操作.我希望这样的东西,但handleAsync不会做你认为它做的事情 - 它在异步运行另一个线程上的回调.在这里返回CompletionStage是不正确的.当天的危害问题:thenApply就是thenCompose因为exceptionally是为了什么?

CompletionStage<String> cf = askPong("cause error").handleAsync((x, t) -> {
    if (t != null) {
        return askPong("Ping");
    } else {
        return x;
    }
});
Run Code Online (Sandbox Code Playgroud)

askPong问演员的地方:

public CompletionStage<String> askPong(String message){
    Future sFuture = ask(actorRef, message, 1000);
    final CompletionStage<String> cs = toJava(sFuture);
    return cs;
} 
Run Code Online (Sandbox Code Playgroud)

java java-8 completable-future

6
推荐指数
2
解决办法
2682
查看次数

标签 统计

completable-future ×1

java ×1

java-8 ×1