diff --git a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java index 66bbf454..5e919d1d 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java +++ b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java @@ -436,6 +436,143 @@ public Cffu> 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 same order of the given Functions arguments. + *

+ * This method is the same as {@link #thenTupleMApplyAsync(Function, Function)} + * except for the fast-fail behavior. + * + * @return the new Cffu + */ + public Cffu> thenTupleMApplyMostSuccessAsync( + long timeout, TimeUnit unit, Function fn1, Function 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 same order of the given Functions arguments. + *

+ * This method is the same as {@link #thenTupleMApplyAsync(Executor, Function, Function)} + * except for the fast-fail behavior. + * + * @return the new Cffu + */ + public Cffu> thenTupleMApplyMostSuccessAsync( + Executor executor, long timeout, TimeUnit unit, Function fn1, Function 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 same order of the given Functions arguments. + *

+ * This method is the same as {@link #thenTupleMApplyAsync(Function, Function, Function)} + * except for the fast-fail behavior. + * + * @return the new Cffu + */ + public Cffu> thenTupleMApplyMostSuccessAsync( + long timeout, TimeUnit unit, Function fn1, + Function fn2, Function 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 same order of the given Functions arguments. + *

+ * This method is the same as {@link #thenTupleMApplyAsync(Executor, Function, Function, Function)} + * except for the fast-fail behavior. + * + * @return the new Cffu + */ + public Cffu> thenTupleMApplyMostSuccessAsync( + Executor executor, long timeout, TimeUnit unit, Function fn1, + Function fn2, Function 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 same order of the given Functions arguments. + *

+ * This method is the same as {@link #thenTupleMApplyAsync(Function, Function, Function, Function)} + * except for the fast-fail behavior. + * + * @return the new Cffu + */ + public Cffu> thenTupleMApplyMostSuccessAsync( + long timeout, TimeUnit unit, Function fn1, Function fn2, + Function fn3, Function 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 same order of the given Functions arguments. + *

+ * This method is the same as {@link #thenTupleMApplyAsync(Executor, Function, Function, Function, Function)} + * except for the fast-fail behavior. + * + * @return the new Cffu + */ + public Cffu> thenTupleMApplyMostSuccessAsync( + Executor executor, long timeout, TimeUnit unit, Function fn1, Function fn2, + Function fn3, Function 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 same order of the given Functions arguments. + *

+ * This method is the same as {@link #thenTupleMApplyAsync(Function, Function, Function, Function, Function)} + * except for the fast-fail behavior. + * + * @return the new Cffu + */ + public Cffu> thenTupleMApplyMostSuccessAsync( + long timeout, TimeUnit unit, Function fn1, + Function fn2, Function fn3, + Function fn4, Function 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 same order of the given Functions arguments. + *

+ * 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 Cffu> thenTupleMApplyMostSuccessAsync( + Executor executor, long timeout, TimeUnit unit, Function fn1, + Function fn2, Function fn3, + Function fn4, Function 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 diff --git a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java index f03a0b56..0916f819 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java @@ -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 @@ -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()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java b/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java index 2642e78b..4243be90 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java @@ -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()); } ////////////////////////////////////////////////////////////////////////////////