/** * Returns a new stage that, when this stage completes either normally or exceptionally, is * executed with this stage's result and exception as arguments to the supplied function. * * <p> When this stage is complete, the given function is invoked with the result (or {@code null} * if none) and the exception (or {@code null} if none) of this stage as arguments, and the * function's result is used to complete the returned stage. * * <p> This differs from * {@link java.util.concurrent.CompletionStage#handle(java.util.function.BiFunction)} 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} * @param <T> the type of the input stage's value. * @param <U> the function's return type * @return the new {@link CompletionStage} * @since 0.1.0 */ public static <T, U> CompletionStage<U> handleCompose( CompletionStage<T> stage, BiFunction<? super T, Throwable, ? extends CompletionStage<U>> fn) { return dereference(stage.handle(fn)); }
/** * Returns a new stage that, when this stage completes either normally or exceptionally, is * executed with this stage's result and exception as arguments to the supplied function. * * <p> When this stage is complete, the given function is invoked with the result (or {@code null} * if none) and the exception (or {@code null} if none) of this stage as arguments, and the * function's result is used to complete the returned stage. * * <p> This differs from * {@link java.util.concurrent.CompletionStage#handle(java.util.function.BiFunction)} 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} * @param <T> the type of the input stage's value. * @param <U> the function's return type * @return the new {@link CompletionStage} * @since 0.1.0 */ public static <T, U> CompletionStage<U> handleCompose( CompletionStage<T> stage, BiFunction<? super T, Throwable, ? extends CompletionStage<U>> fn) { return dereference(stage.handle(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)); }
/** * 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)); }