skip to content
developertype

snippets

filter:96 snippets
java-gen-future·java·general
CompletableFuture<String> future = CompletableFuture
    .supplyAsync(() -> fetchUser(id))
    .thenApply(User::getName)
    .exceptionally(ex -> "unknown");

return future.get(2, TimeUnit.SECONDS);