diff --git a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java index ce30a744..46f1eabd 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -219,6 +219,66 @@ public Cffu> tupleMSupplyFastFai return create(CompletableFutureUtils.tupleMSupplyFastFailAsync(supplier1, supplier2, supplier3, supplier4, supplier5)); } + /** + * Returns a new Cffu that is asynchronously completed + * by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers + * in the same order of the given Suppliers arguments. + *

+ * This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier)} except for the most-success behavior. + * + * @return the new Cffu + */ + @Contract(pure = true) + public Cffu> tupleMSupplyMostSuccessAsync( + long timeout, TimeUnit unit, Supplier supplier1, Supplier supplier2) { + return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(defaultExecutor, timeout, unit,supplier1, supplier2)); + } + + /** + * Returns a new Cffu that is asynchronously completed + * by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers + * in the same order of the given Suppliers arguments. + *

+ * This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier)} except for the most-success behavior. + * + * @return the new Cffu + */ + @Contract(pure = true) + public Cffu> tupleMSupplyMostSuccessAsync( + long timeout, TimeUnit unit, Supplier supplier1, Supplier supplier2, Supplier supplier3) { + return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(defaultExecutor, timeout, unit,supplier1,supplier2,supplier3)); + } + + /** + * Returns a new Cffu that is asynchronously completed + * by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers + * in the same order of the given Suppliers arguments. + *

+ * This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier)} except for the most-success behavior. + * + * @return the new Cffu + */ + @Contract(pure = true) + public Cffu> tupleMSupplyMostSuccessAsync( + long timeout, TimeUnit unit, Supplier supplier1, Supplier supplier2, Supplier supplier3, Supplier supplier4) { + return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(defaultExecutor, timeout, unit,supplier1,supplier2,supplier3,supplier4)); + } + + /** + * Returns a new Cffu that is asynchronously completed + * by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers + * in the same order of the given Suppliers arguments. + *

+ * This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier)} except for the most-success behavior. + * + * @return the new Cffu + */ + @Contract(pure = true) + public Cffu> tupleMSupplyMostSuccessAsync( + long timeout, TimeUnit unit, Supplier supplier1, Supplier supplier2, Supplier supplier3, Supplier supplier4, Supplier supplier5) { + return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(defaultExecutor, timeout, unit,supplier1,supplier2,supplier3,supplier4,supplier5)); + } + /** * Returns a new Cffu that is asynchronously completed * by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers 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 df6891a2..4e2accff 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java @@ -14,7 +14,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.concurrent.*; -import java.util.function.Function; import java.util.function.Supplier; import static io.foldright.cffu.CompletableFutureUtils.failedFuture; @@ -662,6 +661,38 @@ void test_tupleMSupplyAsync() throws Exception { assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); } + @Test + void test_tupleMSupplyMostSuccessAsync() throws Exception { + final Supplier supplier_n = () -> { + sleep(100); + return n; + }; + final Supplier supplier_s = () -> { + sleep(100); + return s; + }; + + final Supplier supplier_d = () -> { + sleep(100); + return d; + }; + final Supplier supplier_an = () -> { + sleep(100); + return anotherN; + }; + final Supplier supplier_nn = () -> { + sleep(100); + return n+n; + }; + assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyMostSuccessAsync(10, TimeUnit.MILLISECONDS,supplier_n, supplier_s).get()); + + assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyMostSuccessAsync(10, TimeUnit.MILLISECONDS,supplier_n, supplier_s, supplier_d).get()); + + assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyMostSuccessAsync(10, TimeUnit.MILLISECONDS,supplier_n, supplier_s, supplier_d, supplier_an).get()); + + assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyMostSuccessAsync(10, TimeUnit.MILLISECONDS,supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); + } + //////////////////////////////////////////////////////////////////////////////// //# Conversion (Static) Methods //