2424import java .util .function .Function ;
2525
2626import net .tascalate .concurrent .Promise ;
27- import net .tascalate .concurrent .Promises ;
2827
2928/**
3029 * Helper class to create a concrete {@link Promise} subclass via delegation
@@ -187,23 +186,23 @@ public Promise<T> exceptionally(Function<Throwable, ? extends T> fn) {
187186 }
188187
189188 public Promise <T > exceptionallyAsync (Function <Throwable , ? extends T > fn ) {
190- return wrap (Promises . exceptionallyApplyAsync (delegate , fn ));
189+ return wrap (exceptionallyAsync (delegate , fn ));
191190 }
192191
193192 public Promise <T > exceptionallyAsync (Function <Throwable , ? extends T > fn , Executor executor ) {
194- return wrap (Promises . exceptionallyApplyAsync (delegate , fn , executor ));
193+ return wrap (exceptionallyAsync (delegate , fn , executor ));
195194 }
196195
197196 public Promise <T > exceptionallyCompose (Function <Throwable , ? extends CompletionStage <T >> fn ) {
198- return wrap (Promises . exceptionallyCompose (delegate , fn ));
197+ return wrap (exceptionallyCompose (delegate , fn ));
199198 }
200199
201200 public Promise <T > exceptionallyComposeAsync (Function <Throwable , ? extends CompletionStage <T >> fn ) {
202- return wrap (Promises . exceptionallyComposeAsync (delegate , fn ));
201+ return wrap (exceptionallyComposeAsync (delegate , fn ));
203202 }
204203
205204 public Promise <T > exceptionallyComposeAsync (Function <Throwable , ? extends CompletionStage <T >> fn , Executor executor ) {
206- return wrap (Promises . exceptionallyComposeAsync (delegate , fn , executor ));
205+ return wrap (exceptionallyComposeAsync (delegate , fn , executor ));
207206 }
208207
209208 public Promise <T > whenComplete (BiConsumer <? super T , ? super Throwable > action ) {
@@ -233,5 +232,46 @@ public <U> Promise<U> handleAsync(BiFunction<? super T, Throwable, ? extends U>
233232 public CompletableFuture <T > toCompletableFuture () {
234233 return delegate .toCompletableFuture ();
235234 }
235+
236+
237+ public static <T > CompletionStage <T > exceptionallyAsync (CompletionStage <T > delegate ,
238+ Function <Throwable , ? extends T > fn ) {
239+ return delegate .handle ((r , ex ) -> ex == null ?
240+ delegate :
241+ delegate .<T >handleAsync ((r1 , ex1 ) -> fn .apply (ex1 )))
242+ .thenCompose (Function .identity ());
243+ }
244+
245+ public static <T > CompletionStage <T > exceptionallyAsync (CompletionStage <T > delegate ,
246+ Function <Throwable , ? extends T > fn , Executor executor ) {
247+ return delegate .handle ((r , ex ) -> ex == null ?
248+ delegate :
249+ delegate .<T >handleAsync ((r1 , ex1 ) -> fn .apply (ex1 ), executor ))
250+ .thenCompose (Function .identity ());
251+ }
252+
253+ public static <T > CompletionStage <T > exceptionallyCompose (CompletionStage <T > delegate ,
254+ Function <Throwable , ? extends CompletionStage <T >> fn ) {
255+ return delegate .handle ((r , ex ) -> ex == null ? delegate : fn .apply (ex ))
256+ .thenCompose (Function .identity ());
257+ }
258+
259+ public static <T > CompletionStage <T > exceptionallyComposeAsync (CompletionStage <T > delegate ,
260+ Function <Throwable , ? extends CompletionStage <T >> fn ) {
261+ return delegate .handle ((r , ex ) -> ex == null ?
262+ delegate :
263+ delegate .handleAsync ((r1 , ex1 ) -> fn .apply (ex1 ))
264+ .thenCompose (Function .identity ()))
265+ .thenCompose (Function .identity ());
266+ }
267+
268+ public static <T > CompletionStage <T > exceptionallyComposeAsync (CompletionStage <T > delegate ,
269+ Function <Throwable , ? extends CompletionStage <T >> fn , Executor executor ) {
270+ return delegate .handle ((r , ex ) -> ex == null ?
271+ delegate :
272+ delegate .handleAsync ((r1 , ex1 ) -> fn .apply (ex1 ), executor )
273+ .thenCompose (Function .identity ()))
274+ .thenCompose (Function .identity ());
275+ }
236276
237277}
0 commit comments