Created
June 30, 2020 21:27
-
-
Save theboreddev/7db762d0c85cc731941a424784bb4cc7 to your computer and use it in GitHub Desktop.
timeout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CompletableFuture<String> subTask = new CompletableFuture<>(); | |
CompletableFuture<Result> chain = CompletableFuture.runAsync(() -> System.out.println("Start")) | |
.thenCombine(subTask, (nil, text) -> { | |
if (text == null || text.isEmpty()) | |
throw new IllegalArgumentException("Text cannot be null or empty!"); | |
return Result.COMPLETED; | |
}) | |
.completeOnTimeout(Result.TIMEOUT, 500, TimeUnit.MILLISECONDS) | |
.exceptionally(exception -> Result.FAILED); | |
final Result result = chain.get(); | |
System.out.println("Result is : " + result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment