|
27 | 27 | public class J8Examples { |
28 | 28 |
|
29 | 29 | public static void main(final String[] argv) throws InterruptedException, ExecutionException { |
30 | | - System.out.println( Duration.ofNanos(Long.MAX_VALUE).toDays() ); |
31 | | - System.out.println( Duration.ofNanos(Long.MAX_VALUE) ); |
32 | | - |
33 | 30 | final TaskExecutorService executorService = TaskExecutors.newFixedThreadPool(3); |
34 | | - |
| 31 | + |
| 32 | + final Promise<Number> p = Promises.any( |
| 33 | + CompletableTask.supplyAsync(() -> awaitAndProduce1(20, 100), executorService), |
| 34 | + CompletableTask.supplyAsync(() -> awaitAndProduce1(-10, 50), executorService) |
| 35 | + ); |
| 36 | + p.whenComplete((r,e) -> { |
| 37 | + System.out.println("Result = " + r + ", Error = " + e); |
| 38 | + }); |
| 39 | + //p.cancel(true); |
| 40 | + |
35 | 41 | Promise<String> retry1 = Promises.poll( |
36 | 42 | () -> "ABC", |
37 | 43 | executorService, RetryPolicy.DEFAULT |
@@ -101,7 +107,9 @@ public static void main(final String[] argv) throws InterruptedException, Execut |
101 | 107 | executorService.submit(() -> awaitAndProduceN(7)), |
102 | 108 | executorService.submit(() -> awaitAndProduceN(8)), |
103 | 109 | executorService.submit(() -> awaitAndProduceN(11)) |
104 | | - ).thenApplyAsync( |
| 110 | + ) |
| 111 | + .defaultAsyncOn(executorService) |
| 112 | + .thenApplyAsync( |
105 | 113 | l -> l.stream().filter(v -> v != null).collect(Collectors.summingInt((Integer i) -> i.intValue())) |
106 | 114 | ) |
107 | 115 | .thenAcceptAsync(J8Examples::onComplete) |
|
0 commit comments