/** * Returns a new stage that, when this stage completes * exceptionally, is executed with this stage's exception as the * argument to the supplied function. Otherwise, if this stage * completes normally, then the returned stage also completes * normally with the same value. * * <p>This differs from * {@link java.util.concurrent.CompletionStage#exceptionally(java.util.function.Function)} * in that the function should return a {@link java.util.concurrent.CompletionStage} rather than * the value directly. * * @param stage the {@link CompletionStage} to compose * @param fn the function to use to compute the value of the * returned {@link CompletionStage} if this stage completed * exceptionally * @param <T> the type of the input stage's value. * @return the new {@link CompletionStage} * @since 0.1.0 */ public static <T> CompletionStage<T> exceptionallyCompose( CompletionStage<T> stage, Function<Throwable, ? extends CompletionStage<T>> fn) { return dereference(wrap(stage).exceptionally(fn)); }
/** * Returns a new stage that, when this stage completes * exceptionally, is executed with this stage's exception as the * argument to the supplied function. Otherwise, if this stage * completes normally, then the returned stage also completes * normally with the same value. * * <p>This differs from * {@link java.util.concurrent.CompletionStage#exceptionally(java.util.function.Function)} * in that the function should return a {@link java.util.concurrent.CompletionStage} rather than * the value directly. * * @param stage the {@link CompletionStage} to compose * @param fn the function to use to compute the value of the * returned {@link CompletionStage} if this stage completed * exceptionally * @param <T> the type of the input stage's value. * @return the new {@link CompletionStage} * @since 0.1.0 */ public static <T> CompletionStage<T> exceptionallyCompose( CompletionStage<T> stage, Function<Throwable, ? extends CompletionStage<T>> fn) { return dereference(wrap(stage).exceptionally(fn)); }