首页 > 解决方案 > completable future in list stop if exception

问题描述

I have a code where I am using completable future in a loop,

list.map(l -> CompletableFuture
            .supplyAsync(() -> [API_CALL])
            .exceptionally(e -> {                   
                throw new RuntimeException("Failed to hit the url");
            }).thenComposeAsync(obj -> anotherApiCall(obj), taskExecutor)));

I am making two API calls one after other in a loop. I want to stop the loop, i.e. map() in case of exception thrown. Is it possible with CompletableFuture?

标签: javaasynchronousexceptioncompletable-future

解决方案


推荐阅读