Skip to content

Commit

Permalink
Merge branch 'dev_hh_catching' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Dec 23, 2024
2 parents 0ffaf2f + e2cb8b5 commit 9d025a9
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 105 deletions.
81 changes: 45 additions & 36 deletions cffu-core/src/main/java/io/foldright/cffu/Cffu.java
Original file line number Diff line number Diff line change
Expand Up @@ -1511,32 +1511,35 @@ public Cffu<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action,
////////////////////////////////////////////////////////////////////////////////

/**
* Returns a new Cffu that, when given stage completes exceptionally with the given exceptionType,
* is executed with given stage's exception as the argument to the supplied function.
* Otherwise, the returned stage contains same result as input Cffu.
* Returns a new Cffu that, when this Cffu completes exceptionally with the given exceptionType,
* is executed with the exception from this Cffu as the argument to the supplied function.
* Otherwise, the returned Cffu contains same result as this Cffu.
*
* @param exceptionType the exception type that triggers use of {@code fallback}. The exception type is matched
* against the input's exception. To avoid hiding bugs and other unrecoverable errors,
* against the exception from this Cffu. <strong>"the exception from this Cffu"</strong> means
* the cause of the {@link ExecutionException} thrown by {@code get()} or, if {@code get()} throws a
* different kind of exception, that exception itself. To avoid hiding bugs and other unrecoverable errors,
* callers should prefer more specific types, avoiding {@code Throwable.class} in particular.
* @param fallback the Function to be called if {@code input} fails with the expected exception type.
* The function's argument is the input's exception.
* @param fallback the Function to be called if this Cffu fails with the expected exception type.
* The function's argument is the exception from this Cffu.
* @see Futures#catching the equivalent Guava method catching()
*/
public <X extends Throwable> Cffu<T> catching(Class<X> exceptionType, Function<? super X, ? extends T> fallback) {
return resetCf(CompletableFutureUtils.catching(cf, exceptionType, fallback));
}

/**
* Returns a new Cffu that, when given stage completes exceptionally with the given exceptionType,
* is executed with given stage's exception as the argument to the supplied function,
* using the given stage's default asynchronous execution facility.
* Otherwise, the returned stage contains same result as input Cffu.
* Returns a new Cffu that, when this Cffu completes exceptionally with the given exceptionType,
* is executed with the exception from this Cffu as the argument to the supplied function, using {@link #defaultExecutor()}.
* Otherwise, the returned Cffu contains same result as this Cffu.
*
* @param exceptionType the exception type that triggers use of {@code fallback}. The exception type is matched
* against the input's exception. To avoid hiding bugs and other unrecoverable errors,
* against the exception from this Cffu. <strong>"the exception from this Cffu"</strong> means
* the cause of the {@link ExecutionException} thrown by {@code get()} or, if {@code get()} throws a
* different kind of exception, that exception itself. To avoid hiding bugs and other unrecoverable errors,
* callers should prefer more specific types, avoiding {@code Throwable.class} in particular.
* @param fallback the Function to be called if {@code input} fails with the expected exception type.
* The function's argument is the input's exception.
* @param fallback the Function to be called if this Cffu fails with the expected exception type.
* The function's argument is the exception from this Cffu.
* @see Futures#catching the equivalent Guava method catching()
*/
public <X extends Throwable> Cffu<T> catchingAsync(
Expand All @@ -1545,15 +1548,17 @@ public <X extends Throwable> Cffu<T> catchingAsync(
}

/**
* Returns a new Cffu that, when given stage completes exceptionally with the given exceptionType,
* is executed with given stage's exception as the argument to the supplied function, using the supplied Executor.
* Otherwise, the returned stage contains same result as input Cffu.
* Returns a new Cffu that, when this Cffu completes exceptionally with the given exceptionType,
* is executed with the exception from this Cffu as the argument to the supplied function, using the supplied Executor.
* Otherwise, the returned Cffu contains same result as this Cffu.
*
* @param exceptionType the exception type that triggers use of {@code fallback}. The exception type is matched
* against the input's exception. To avoid hiding bugs and other unrecoverable errors,
* against the exception from this Cffu. <strong>"the exception from this Cffu"</strong> means
* the cause of the {@link ExecutionException} thrown by {@code get()} or, if {@code get()} throws a
* different kind of exception, that exception itself. To avoid hiding bugs and other unrecoverable errors,
* callers should prefer more specific types, avoiding {@code Throwable.class} in particular.
* @param fallback the Function to be called if {@code input} fails with the expected exception type.
* The function's argument is the input's exception.
* @param fallback the Function to be called if this Cffu fails with the expected exception type.
* The function's argument is the exception from this Cffu.
* @param executor the executor to use for asynchronous execution
* @see Futures#catching the equivalent Guava method catching()
*/
Expand Down Expand Up @@ -1854,14 +1859,16 @@ public <U> Cffu<U> thenComposeAsync(Function<? super T, ? extends CompletionStag
}

/**
* Returns a new Cffu that, when given stage completes exceptionally with the given exceptionType,
* is composed using the results of the supplied function applied to given stage's exception.
* Returns a new Cffu that, when this Cffu completes exceptionally with the given exceptionType,
* is composed using the results of the supplied function applied to the exception from this Cffu.
*
* @param exceptionType the exception type that triggers use of {@code fallback}. The exception type is matched
* against the input's exception. To avoid hiding bugs and other unrecoverable errors,
* against the exception from this Cffu. <strong>"the exception from this Cffu"</strong> means
* the cause of the {@link ExecutionException} thrown by {@code get()} or, if {@code get()} throws a
* different kind of exception, that exception itself. To avoid hiding bugs and other unrecoverable errors,
* callers should prefer more specific types, avoiding {@code Throwable.class} in particular.
* @param fallback the Function to be called if {@code input} fails with the expected exception type.
* The function's argument is the input's exception.
* @param fallback the Function to be called if this Cffu fails with the expected exception type.
* The function's argument is the exception from this Cffu.
* @see Futures#catchingAsync the equivalent Guava method catchingAsync()
*/
public <X extends Throwable> Cffu<T> catchingCompose(
Expand All @@ -1870,15 +1877,16 @@ public <X extends Throwable> Cffu<T> catchingCompose(
}

/**
* Returns a new Cffu that, when given stage completes exceptionally with the given exceptionType,
* is composed using the results of the supplied function applied to given stage's exception,
* using given stage's default asynchronous execution facility.
* Returns a new Cffu that, when this Cffu completes exceptionally with the given exceptionType,
* is composed using the results of the supplied function applied to the exception from this Cffu using {@link #defaultExecutor()}.
*
* @param exceptionType the exception type that triggers use of {@code fallback}. The exception type is matched
* against the input's exception. To avoid hiding bugs and other unrecoverable errors,
* against the exception from this Cffu. <strong>"the exception from this Cffu"</strong> means
* the cause of the {@link ExecutionException} thrown by {@code get()} or, if {@code get()} throws a
* different kind of exception, that exception itself. To avoid hiding bugs and other unrecoverable errors,
* callers should prefer more specific types, avoiding {@code Throwable.class} in particular.
* @param fallback the Function to be called if {@code input} fails with the expected exception type.
* The function's argument is the input's exception.
* @param fallback the Function to be called if this Cffu fails with the expected exception type.
* The function's argument is the exception from this Cffu.
* @see Futures#catchingAsync the equivalent Guava method catchingAsync()
*/
public <X extends Throwable> Cffu<T> catchingComposeAsync(
Expand All @@ -1887,15 +1895,16 @@ public <X extends Throwable> Cffu<T> catchingComposeAsync(
}

/**
* Returns a new Cffu that, when given stage completes exceptionally with the given exceptionType,
* is composed using the results of the supplied function applied to given's exception,
* using the supplied Executor.
* Returns a new Cffu that, when this Cffu completes exceptionally with the given exceptionType,
* is composed using the results of the supplied function applied to the exception from this Cffu, using the supplied Executor.
*
* @param exceptionType the exception type that triggers use of {@code fallback}. The exception type is matched
* against the input's exception. To avoid hiding bugs and other unrecoverable errors,
* against the exception from this Cffu. <strong>"the exception from this Cffu"</strong> means
* the cause of the {@link ExecutionException} thrown by {@code get()} or, if {@code get()} throws a
* different kind of exception, that exception itself. To avoid hiding bugs and other unrecoverable errors,
* callers should prefer more specific types, avoiding {@code Throwable.class} in particular.
* @param fallback the Function to be called if {@code input} fails with the expected exception type.
* The function's argument is the input's exception.
* @param fallback the Function to be called if this Cffu fails with the expected exception type.
* The function's argument is the exception from this Cffu.
* @param executor the executor to use for asynchronous execution
* @see Futures#catchingAsync the equivalent Guava method catchingAsync()
*/
Expand Down
Loading

0 comments on commit 9d025a9

Please sign in to comment.