@@ -30,7 +30,6 @@ public class J8Examples {
3030
3131 public static void main (final String [] argv ) throws InterruptedException , ExecutionException {
3232 final TaskExecutorService executorService = TaskExecutors .newFixedThreadPool (6 );
33-
3433 @ SuppressWarnings ("unused" )
3534 Promise <Void > t1 = Promises .retry (() -> System .out .println ("Hello!" ), executorService , RetryPolicy .DEFAULT );
3635
@@ -64,13 +63,7 @@ public static void main(final String[] argv) throws InterruptedException, Execut
6463 //Promise<Object> k = Promises.failure(new RuntimeException());
6564 k .dependent ().delay (Duration .ofMillis (1 ), true ).whenComplete ((r , e ) -> System .out .println (Thread .currentThread () + " ==> " + r + ", " + e ));
6665
67- /*
68- if (System.out != null) {
69- Thread.sleep(1000);
70- executorService.shutdown();
71- return;
72- }
73- */
66+
7467
7568 Promise <Object > k1 = CompletableTask .supplyAsync (() -> produceStringSlow ("-onTimeout1" ), executorService );
7669 k1 .onTimeout ("ALTERNATE1" , Duration .ofMillis (50 ))
@@ -142,27 +135,26 @@ public static void main(final String[] argv) throws InterruptedException, Execut
142135 task2 ,
143136 (a ,b ) -> a + b
144137 )
145- .thenAcceptAsync (J8Examples ::onComplete )
146- .exceptionally (J8Examples ::onError )
138+ .thenAcceptAsync (J8Examples ::onComplete )
139+ .exceptionally (J8Examples ::onError )
147140 ;
148141 if (i == 10 ) {
149142 Thread .sleep (200 );
150143 task1 .cancel (true );
151144 }
152145 }
153-
154-
146+
155147 Promise <Integer > intermidiate ;
156148 Promises .atLeast (
157- 4 , //Change to 5 or 6 to see the difference -- will end up exceptionally
158- executorService .submit (() -> awaitAndProduceN (2 )),
159- intermidiate =
160- executorService .submit (() -> awaitAndProduceN (3 )).thenAcceptAsync (J8Examples ::multByX ).thenApply ((v ) -> 1234 ),
161- executorService .submit (() -> awaitAndProduceN (5 )),
162- executorService .submit (() -> awaitAndProduceN (6 )),
163- executorService .submit (() -> awaitAndProduceN (7 )),
164- executorService .submit (() -> awaitAndProduceN (8 )),
165- executorService .submit (() -> awaitAndProduceN (11 ))
149+ 4 , //Change to 5 or 6 to see the difference -- will end up exceptionally
150+ executorService .submit (() -> awaitAndProduceN (2 )),
151+ intermidiate =
152+ executorService .submit (() -> awaitAndProduceN (3 )).thenAcceptAsync (J8Examples ::multByX ).thenApply ((v ) -> 1234 ),
153+ executorService .submit (() -> awaitAndProduceN (5 )),
154+ executorService .submit (() -> awaitAndProduceN (6 )),
155+ executorService .submit (() -> awaitAndProduceN (7 )),
156+ executorService .submit (() -> awaitAndProduceN (8 )),
157+ executorService .submit (() -> awaitAndProduceN (11 ))
166158 )
167159 .defaultAsyncOn (executorService )
168160 .thenApplyAsync (
@@ -182,6 +174,16 @@ public static void main(final String[] argv) throws InterruptedException, Execut
182174
183175 System .out .println ("Intermediate result: " + intermidiate .toCompletableFuture ().get ());
184176
177+ Promise <?> xt = CompletableTask
178+ .supplyAsync (() -> "" + awaitAndProduceN (11 ), executorService )
179+ .defaultAsyncOn (executorService )
180+ .onCancel (() -> System .out .println ("CANCELLED!!!" ))
181+ .dependent ()
182+ .onTimeout ("XYZ" , Duration .ofMillis (20 ), true , true )
183+ .thenAccept (v -> System .out .println ("Value produced via timeout: " + v ))
184+ ;
185+ //xt.cancel(true);
186+ System .out .println (xt );
185187
186188 // Suicidal task to close gracefully
187189 executorService .submit (() -> {
0 commit comments