IZ
CompletableFuture<Integer> fastRequest =
CompletableFuture.supplyAsync(() -> new Random().nextInt(100));
CompletableFuture<Integer> slowRequest =
CompletableFuture.supplyAsync(
() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return 42;
});
return fastRequest.thenApply(
result -> {
if (result == 42) {
return result;
}
try {
return slowRequest.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
});
}
как сделать эту логику полностью неблокируемой?
