Skip to content

Commit

Permalink
refactor: rename all*OfFastFail methods to all*FastFailOf, consis…
Browse files Browse the repository at this point in the history
…tent with other methods 🔠
  • Loading branch information
oldratlee committed Jun 30, 2024
1 parent 9d2b07d commit 4587d0a
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 116 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
- `allResultsOfFastFail`/`allResultsOf`方法:返回多个`CF`的结果,而不是无返回结果`Void``CompletableFuture#allOf()`
- `allTupleOfFastFail`/`allTupleOf`方法:返回多个`CF`不同类型的结果,而不是同一类型(`allResultsOf`
- 更高效灵活的并发执行策略,如
- `allResultsOfFastFail`/`allOfFastFail`方法:有`CF`失败时快速返回,而不再等待所有`CF`运行完成(`allOf`
- `allResultsOfFastFail`/`allFastFailOf`方法:有`CF`失败时快速返回,而不再等待所有`CF`运行完成(`allOf`
- `anySuccessOf`方法:返回首个成功的`CF`结果,而不是首个完成(但可能失败)的`CF``anyOf`
- `mostSuccessResultsOf`方法:返回指定时间内成功`CF`的结果,忽略失败或还没有运行完成的`CF`(使用缺省值)
- 更安全的使用方式,如
Expand Down Expand Up @@ -434,7 +434,7 @@ public class DefaultExecutorSettingForCffu {
>
> `JavaScript Promise`提供了4个并发执行方法:
>
> - [`Promise.all()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all):等待所有`Promise`运行成功,只要有一个失败就立即返回失败(对应`cffu``allOfFastFail`方法)
> - [`Promise.all()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all):等待所有`Promise`运行成功,只要有一个失败就立即返回失败(对应`cffu``allFastFailOf`方法)
> - [`Promise.allSettled()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled):等待所有`Promise`运行完成,不管成功失败(对应`cffu``allOf`方法)
> - [`Promise.any()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any):赛马模式,立即返回首个成功的`Promise`(对应`cffu``anySuccessOf`方法)
> - [`Promise.race()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race):赛马模式,立即返回首个完成的`Promise`(对应`cffu``anyOf`方法)
Expand Down Expand Up @@ -462,7 +462,7 @@ public class ConcurrencyStrategyDemo {
final Cffu<Integer> failed = cffuFactory.failedFuture(new RuntimeException("Bang!"));

// Result type is Void!
Cffu<Void> cffuAll = cffuFactory.allOfFastFail(successAfterLongTime, failed);
Cffu<Void> cffuAll = cffuFactory.allFastFailOf(successAfterLongTime, failed);

Cffu<List<Integer>> fastFailed = cffuFactory.allResultsOfFastFail(successAfterLongTime, failed);
// fast failed without waiting successAfterLongTime
Expand All @@ -472,7 +472,7 @@ public class ConcurrencyStrategyDemo {
System.out.println(anySuccessOf.get());

////////////////////////////////////////////////////////////////////////
// or CompletableFutureUtils#allOfFastFail / allResultsOfFastFail
// or CompletableFutureUtils#allFastFailOf / allResultsOfFastFail
// CompletableFutureUtils#anySuccessOf
////////////////////////////////////////////////////////////////////////
final CompletableFuture<Integer> successAfterLongTimeCf = CompletableFuture.supplyAsync(() -> {
Expand All @@ -482,7 +482,7 @@ public class ConcurrencyStrategyDemo {
final CompletableFuture<Integer> failedCf = CompletableFutureUtils.failedFuture(new RuntimeException("Bang!"));

// Result type is Void!
CompletableFuture<Void> cfAll = CompletableFutureUtils.allOfFastFail(successAfterLongTimeCf, failedCf);
CompletableFuture<Void> cfAll = CompletableFutureUtils.allFastFailOf(successAfterLongTimeCf, failedCf);

CompletableFuture<List<Integer>> fastFailedCf = CompletableFutureUtils.allResultsOfFastFail(successAfterLongTimeCf, failedCf);
// fast failed without waiting successAfterLongTime
Expand Down
31 changes: 24 additions & 7 deletions cffu-core/src/main/java/io/foldright/cffu/Cffu.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public final <U> Cffu<List<U>> thenMApplyFastFailAsync(Function<? super T, ? ext
* (with the given stage's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @param fns the functions to use to compute the values of the returned Cffu
* @param executor executor
* @param <U> the functions' return type
* @return the new Cffu
*/
Expand Down Expand Up @@ -314,8 +314,9 @@ public final <U> Cffu<List<U>> thenMApplyAsync(Function<? super T, ? extends U>.
* (with the given stage's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param fns the functions to use to compute the values of the returned Cffu
* @param <U> the functions' return type
* @param executor the executor to use for asynchronous execution
* @param fns the functions to use to compute the values of the returned Cffu
* @param <U> the functions' return type
* @return the new Cffu
*/
@SafeVarargs
Expand All @@ -340,7 +341,8 @@ public final Cffu<Void> thenMAcceptAsync(Consumer<? super T>... actions) {
* Returns a new Cffu that, when the given stage completes normally,
* is executed using the given Executor, with the given stage's result as the argument to the given actions.
*
* @param actions the actions to perform before completing the returned Cffu
* @param executor the executor to use for asynchronous execution
* @param actions the actions to perform before completing the returned Cffu
* @return the new Cffu
*/
@SafeVarargs
Expand All @@ -365,7 +367,8 @@ public final Cffu<Void> thenMAcceptFastFailAsync(Consumer<? super T>... actions)
* Returns a new Cffu that, when the given stage completes normally,
* is executed using the given Executor, with the given stage's result as the argument to the given actions.
*
* @param actions the actions to perform before completing the returned Cffu
* @param executor the executor to use for asynchronous execution
* @param actions the actions to perform before completing the returned Cffu
* @return the new Cffu
*/
@SafeVarargs
Expand All @@ -390,7 +393,8 @@ public Cffu<Void> thenMRunFastFailAsync(Runnable... actions) {
* Returns a new Cffu that, when the given stage completes normally,
* executes the given actions using the given Executor.
*
* @param actions the actions to perform before completing the returned Cffu
* @param executor the executor to use for asynchronous execution
* @param actions the actions to perform before completing the returned Cffu
* @return the new Cffu
* @see CompletableFuture#thenRunAsync(Runnable, Executor)
*/
Expand All @@ -414,7 +418,8 @@ public Cffu<Void> thenMRunAsync(Runnable... actions) {
* Returns a new Cffu that, when the given stage completes normally,
* executes the given actions using the given Executor.
*
* @param actions the actions to perform before completing the returned Cffu
* @param executor the executor to use for asynchronous execution
* @param actions the actions to perform before completing the returned Cffu
* @return the new Cffu
* @see CompletableFuture#thenRunAsync(Runnable, Executor)
*/
Expand Down Expand Up @@ -446,6 +451,7 @@ public <U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyFastFailAsync(
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyFastFailAsync(
Expand Down Expand Up @@ -473,6 +479,7 @@ public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyFastFailAsync(
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyFastFailAsync(
Expand Down Expand Up @@ -501,6 +508,7 @@ public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyFastFailAsyn
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyFastFailAsync(
Expand Down Expand Up @@ -530,6 +538,7 @@ public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyFast
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyFastFailAsync(
Expand Down Expand Up @@ -558,6 +567,7 @@ public <U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyMostSuccessAsync(
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyMostSuccessAsync(
Expand Down Expand Up @@ -586,6 +596,7 @@ public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyMostSuccessAsync(
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyMostSuccessAsync(
Expand Down Expand Up @@ -615,6 +626,7 @@ public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyMostSuccessA
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyMostSuccessAsync(
Expand Down Expand Up @@ -645,6 +657,7 @@ public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyMost
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyMostSuccessAsync(
Expand Down Expand Up @@ -673,6 +686,7 @@ public <U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyAsync(
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyAsync(
Expand Down Expand Up @@ -700,6 +714,7 @@ public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyAsync(
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyAsync(
Expand Down Expand Up @@ -728,6 +743,7 @@ public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyAsync(
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyAsync(
Expand Down Expand Up @@ -757,6 +773,7 @@ public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyAsyn
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @param executor the executor to use for asynchronous execution
* @return the new Cffu
*/
public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyAsync(
Expand Down
Loading

0 comments on commit 4587d0a

Please sign in to comment.