Skip to content

Commit

Permalink
Cffu 补充mostof模式
Browse files Browse the repository at this point in the history
  • Loading branch information
huhaosumail committed Jun 25, 2024
1 parent 6993c42 commit 3c5a86e
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 12 deletions.
137 changes: 137 additions & 0 deletions cffu-core/src/main/java/io/foldright/cffu/Cffu.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,143 @@ public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyFast
return reset0(CompletableFutureUtils.thenTupleMApplyFastFailAsync(cf, executor, fn1, fn2, fn3, fn4, fn5));
}


/**
* Returns a new Cffu that, when this Cffu completes normally, is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
public <U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyMostSuccessAsync(
long timeout, TimeUnit unit, Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2) {
return thenTupleMApplyMostSuccessAsync(fac.defaultExecutor(), timeout, unit, fn1, fn2);
}

/**
* Returns a new Cffu that, when this Cffu completes normally, is executed using the supplied Executor,
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(Executor, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
public <U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyMostSuccessAsync(
Executor executor, long timeout, TimeUnit unit, Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2) {
return reset0(CompletableFutureUtils.thenTupleMApplyMostSuccessAsync(cf, executor, timeout, unit, fn1, fn2));
}

/**
* Returns a new Cffu that, when this Cffu completes normally, is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyMostSuccessAsync(
long timeout, TimeUnit unit, Function<? super T, ? extends U1> fn1,
Function<? super T, ? extends U2> fn2, Function<? super T, ? extends U3> fn3) {
return thenTupleMApplyMostSuccessAsync(fac.defaultExecutor(), timeout, unit, fn1, fn2, fn3);
}

/**
* Returns a new Cffu that, when this Cffu completes normally, is executed using the supplied Executor,
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(Executor, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyMostSuccessAsync(
Executor executor, long timeout, TimeUnit unit, Function<? super T, ? extends U1> fn1,
Function<? super T, ? extends U2> fn2, Function<? super T, ? extends U3> fn3) {
return reset0(CompletableFutureUtils.thenTupleMApplyMostSuccessAsync(cf, executor, timeout, unit, fn1, fn2, fn3));
}

/**
* Returns a new Cffu that, when this Cffu completes normally, is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(Function, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyMostSuccessAsync(
long timeout, TimeUnit unit, Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2,
Function<? super T, ? extends U3> fn3, Function<? super T, ? extends U4> fn4) {
return thenTupleMApplyMostSuccessAsync(fac.defaultExecutor(), timeout, unit, fn1, fn2, fn3, fn4);
}

/**
* Returns a new Cffu that, when this Cffu completes normally, is executed using the supplied Executor,
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(Executor, Function, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyMostSuccessAsync(
Executor executor, long timeout, TimeUnit unit, Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2,
Function<? super T, ? extends U3> fn3, Function<? super T, ? extends U4> fn4) {
return reset0(CompletableFutureUtils.thenTupleMApplyMostSuccessAsync(cf, executor, timeout, unit, fn1, fn2, fn3, fn4));
}

/**
* Returns a new Cffu that, when this Cffu completes normally, is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(Function, Function, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyMostSuccessAsync(
long timeout, TimeUnit unit, Function<? super T, ? extends U1> fn1,
Function<? super T, ? extends U2> fn2, Function<? super T, ? extends U3> fn3,
Function<? super T, ? extends U4> fn4, Function<? super T, ? extends U5> fn5) {
return thenTupleMApplyMostSuccessAsync(fac.defaultExecutor(), timeout, unit, fn1, fn2, fn3, fn4, fn5);
}

/**
* Returns a new Cffu that, when this Cffu completes normally, is executed using the supplied Executor,
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(Executor, Function, Function, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyMostSuccessAsync(
Executor executor, long timeout, TimeUnit unit, Function<? super T, ? extends U1> fn1,
Function<? super T, ? extends U2> fn2, Function<? super T, ? extends U3> fn3,
Function<? super T, ? extends U4> fn4, Function<? super T, ? extends U5> fn5) {
return reset0(CompletableFutureUtils.thenTupleMApplyMostSuccessAsync(cf, executor, timeout, unit, fn1, fn2, fn3, fn4, fn5));
}

/**
* Returns a new Cffu that, when this Cffu completes normally, is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
Expand Down
24 changes: 12 additions & 12 deletions cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -699,24 +699,24 @@ void test_tupleMSupplyAsync() throws Exception {
return n + n;
};
assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyAsync(supplier_n, supplier_s).get());
assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyAsync(executorService,supplier_n, supplier_s).get());
assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyAsync(executorService, supplier_n, supplier_s).get());
assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s).get());
assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyFastFailAsync(executorService,supplier_n, supplier_s).get());
assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyFastFailAsync(executorService, supplier_n, supplier_s).get());

assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyAsync(supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyAsync(executorService,supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyAsync(executorService, supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyFastFailAsync(executorService,supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyFastFailAsync(executorService, supplier_n, supplier_s, supplier_d).get());

assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyAsync(supplier_n, supplier_s, supplier_d, supplier_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyAsync(executorService,supplier_n, supplier_s, supplier_d, supplier_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s, supplier_d, supplier_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyFastFailAsync(executorService,supplier_n, supplier_s, supplier_d, supplier_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyFastFailAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an).get());

assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyAsync(supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyAsync(executorService,supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyFastFailAsync(executorService,supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyFastFailAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get());
}

@Test
Expand All @@ -743,16 +743,16 @@ void test_tupleMSupplyMostSuccessAsync() throws Exception {
return n + n;
};
assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, supplier_n, supplier_s).get());
assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyMostSuccessAsync(executorService,100, TimeUnit.MILLISECONDS, supplier_n, supplier_s).get());
assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, supplier_n, supplier_s).get());

assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyMostSuccessAsync(executorService,100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d).get());

assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyMostSuccessAsync(executorService,100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an).get());

assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyMostSuccessAsync(executorService,100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 16 additions & 0 deletions cffu-core/src/test/java/io/foldright/cffu/CffuTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,32 @@ void test_thenTupleMApplyAsync() throws Exception {
return n + n;
};
assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyAsync(function_n, function_s).get());
assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyAsync(executorService, function_n, function_s).get());
assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyFastFailAsync(function_n, function_s).get());
assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s).get());
assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s).get());
assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s).get());

assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyAsync(function_n, function_s, function_d).get());
assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyAsync(executorService, function_n, function_s, function_d).get());
assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyFastFailAsync(function_n, function_s, function_d).get());
assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s, function_d).get());
assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s, function_d).get());
assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s, function_d).get());

assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyAsync(function_n, function_s, function_d, function_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyAsync(executorService, function_n, function_s, function_d, function_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyFastFailAsync(function_n, function_s, function_d, function_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s, function_d, function_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an).get());

assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyAsync(function_n, function_s, function_d, function_an, function_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyAsync(executorService, function_n, function_s, function_d, function_an, function_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyFastFailAsync(function_n, function_s, function_d, function_an, function_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s, function_d, function_an, function_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an, function_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an, function_nn).get());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 3c5a86e

Please sign in to comment.