diff --git a/README.md b/README.md index 2b9f3fb5..a247dba1 100644 --- a/README.md +++ b/README.md @@ -70,8 +70,8 @@ - ☘️ **补全业务使用中缺失的功能** - 更方便的功能,如 - - `cffuAllOf`/`allOfWithResult`方法:返回多个`CF`的结果,而不是无返回结果`Void`(`allOf`) - - `cffuCombine`/`combine`方法:返回多个`CF`不同类型的结果,而不是同一类型(`cffuAllOf`/`allOfWithResult`) + - `allResultsOf`方法:返回多个`CF`的结果,而不是无返回结果`Void`(`CompletableFuture#allOf()`) + - `cffuCombine`/`combine`方法:返回多个`CF`不同类型的结果,而不是同一类型(`allResultsOf`) - 更高效灵活的并发执行策略,如 - `allOfFastFail`方法:有`CF`失败时快速返回,而不再等待所有`CF`运行完成(`allOf`) - `anyOfSuccess`方法:返回首个成功的`CF`结果,而不是首个完成(但可能失败)的`CF`(`anyOf`) @@ -277,7 +277,7 @@ fun main() { `CompletableFuture`的`allOf`方法没有返回结果,只是返回`Void`,不方便获得所运行的多个`CF`结果。 \# 要再通过入参`CF`的`get`方法来获取结果。 -`cffu`的`cffuAllOf`/`allOfWithResult`方法提供了返回多个`CF`结果的功能。 +`cffu`的`allResultsOf`方法提供了返回多个`CF`结果的功能。 示例代码如下: @@ -288,7 +288,7 @@ public class AllOfWithResultDemo { public static void main(String[] args) { ////////////////////////////////////////////////// - // CffuFactory#cffuAllOf + // CffuFactory#allOf ////////////////////////////////////////////////// Cffu cffu1 = cffuFactory.completedFuture(21); Cffu cffu2 = cffuFactory.completedFuture(42); @@ -298,11 +298,11 @@ public class AllOfWithResultDemo { // the result can be got by input argument `cf1.get()`, but it's cumbersome. // so we can see a lot the util methods to enhance allOf with result in our project. - Cffu> allOfWithResult = cffuFactory.cffuAllOf(cffu1, cffu2); - System.out.println(allOfWithResult.get()); + Cffu> allResults = cffuFactory.allResultsOf(cffu1, cffu2); + System.out.println(allResults.get()); ////////////////////////////////////////////////// - // or CompletableFutureUtils#allOfWithResult + // or CompletableFutureUtils#allResultsOf ////////////////////////////////////////////////// CompletableFuture cf1 = CompletableFuture.completedFuture(21); CompletableFuture cf2 = CompletableFuture.completedFuture(42); @@ -310,8 +310,8 @@ public class AllOfWithResultDemo { CompletableFuture allOf = CompletableFuture.allOf(cf1, cf2); // Result type is Void!! - CompletableFuture> allOfWithResult2 = CompletableFutureUtils.allOfWithResult(cf1, cf2); - System.out.println(allOfWithResult2.get()); + CompletableFuture> allResults2 = CompletableFutureUtils.allOfWithResult(cf1, cf2); + System.out.println(allResults2.get()); } } ``` @@ -414,7 +414,7 @@ public class DefaultExecutorSettingForCffu { - `CompletableFuture`的`allOf`方法会等待所有输入`CF`运行完成;即使有`CF`失败了也要等待后续`CF`运行完成,再返回一个失败的`CF`。 - 对于业务逻辑来说,这样失败且继续等待策略,减慢了业务响应性;会希望如果有输入`CF`失败了,则快速失败不再做于事无补的等待 - - `cffu`提供了相应的`cffuAllOfFastFail`/`allOfFastFail`方法 + - `cffu`提供了相应的`allResultsOfFastFail`/`allOfFastFail`方法 - `allOf`/`allOfFastFail`两者都是,只有当所有的输入`CF`都成功时,才返回成功结果 - `CompletableFuture`的`anyOf`方法返回首个完成的`CF`(不会等待后续没有完成的`CF`,赛马模式);即使首个完成的`CF`是失败的,也会返回这个失败的`CF`结果。 - 对于业务逻辑来说,会希望赛马模式返回首个成功的`CF`结果,而不是首个完成但失败的`CF` @@ -443,7 +443,7 @@ public class ConcurrencyStrategyDemo { public static void main(String[] args) throws Exception { //////////////////////////////////////////////////////////////////////// - // CffuFactory#cffuAllOfFastFail / allOfFastFail + // CffuFactory#allResultsOfFastFail / allOfFastFail // CffuFactory#anyOfSuccess //////////////////////////////////////////////////////////////////////// final Cffu successAfterLongTime = cffuFactory.supplyAsync(() -> { @@ -454,7 +454,7 @@ public class ConcurrencyStrategyDemo { // Result type is Void! Cffu cffuAll = cffuFactory.allOfFastFail(successAfterLongTime, failed); - Cffu> fastFailed = cffuFactory.cffuAllOfFastFail(successAfterLongTime, failed); + Cffu> fastFailed = cffuFactory.allResultsOfFastFail(successAfterLongTime, failed); // fast failed without waiting successAfterLongTime System.out.println(fastFailed.exceptionNow()); 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 ccb7e86a..3d8ce21d 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -312,7 +312,7 @@ public final Cffu[] asCffuArray(CompletionStage... stages) { *

* if you need the results of given Cffus, prefer below methods: *

    - *
  1. {@link #cffuAllOf(Cffu[])} + *
  2. {@link #allResultsOf(Cffu[])} *
  3. {@link #cffuCombine(Cffu, Cffu)} / {@link #cffuCombine(Cffu, Cffu, Cffu, Cffu, Cffu)} * (provided overloaded methods with 2~5 input) *
@@ -324,7 +324,7 @@ public final Cffu[] asCffuArray(CompletionStage... stages) { * @param cfs the Cffus * @return a new Cffu that is completed when all the given Cffus complete * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #cffuAllOf(Cffu[]) + * @see #allResultsOf(Cffu[]) * @see #cffuCombine(Cffu, Cffu) * @see #cffuCombine(Cffu, Cffu, Cffu) * @see #cffuCombine(Cffu, Cffu, Cffu, Cffu) @@ -349,7 +349,7 @@ public Cffu allOf(Cffu... cfs) { *

* if you need the results of given CompletableFutures, prefer below methods: *

    - *
  1. {@link #cffuAllOf(CompletableFuture[])} + *
  2. {@link #allResultsOf(CompletableFuture[])} *
  3. {@link #cffuCombine(CompletableFuture, CompletableFuture)} / * {@link #cffuCombine(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture)} * (provided overloaded methods with 2~5 input) @@ -359,7 +359,7 @@ public Cffu allOf(Cffu... cfs) { * @return a new Cffu that is completed when all the given CompletableFutures complete * @throws NullPointerException if the array or any of its elements are {@code null} * @see #allOf(Cffu[]) - * @see #cffuAllOf(CompletableFuture[]) + * @see #allResultsOf(CompletableFuture[]) * @see #cffuCombine(CompletableFuture, CompletableFuture) * @see #cffuCombine(CompletableFuture, CompletableFuture, CompletableFuture) * @see #cffuCombine(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) @@ -418,7 +418,7 @@ public Cffu allOfFastFail(Cffu... cfs) { * @return a new Cffu that is successful when all the given CompletableFutures success * @throws NullPointerException if the array or any of its elements are {@code null} * @see #allOfFastFail(Cffu[]) - * @see #cffuAllOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(CompletableFuture[]) * @see CompletableFutureUtils#allOfFastFail(CompletableFuture[]) */ @Contract(pure = true) @@ -570,7 +570,7 @@ public Executor delayedExecutor(long delay, TimeUnit unit, Executor executor) { //# New type-safe allOf/anyOf Factory Methods // method name prefix with `cffu` // - // - cffuAllOf + // - allResultsOf //////////////////////////////////////////////////////////////////////////////// /** @@ -592,8 +592,8 @@ public Executor delayedExecutor(long delay, TimeUnit unit, Executor executor) { @Contract(pure = true) @SafeVarargs @SuppressWarnings({"rawtypes", "unchecked"}) - public final Cffu> cffuAllOf(Cffu... cfs) { - return cffuAllOf(toCompletableFutureArray((Cffu[]) cfs)); + public final Cffu> allResultsOf(Cffu... cfs) { + return allResultsOf(toCompletableFutureArray((Cffu[]) cfs)); } /** @@ -603,28 +603,28 @@ public final Cffu> cffuAllOf(Cffu... cfs) { * also does so, with a CompletionException holding this exception as its cause. * If no CompletableFutures are provided, returns a Cffu completed with the value empty list. *

    - * Same as {@link #cffuAllOf(Cffu[])} with overloaded argument type {@link CompletableFuture}. + * Same as {@link #allResultsOf(Cffu[])} with overloaded argument type {@link CompletableFuture}. * * @param cfs the CompletableFutures * @return a new Cffu that is completed when all the given CompletableFutures complete * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #cffuAllOf(Cffu[]) + * @see #allResultsOf(Cffu[]) */ @Contract(pure = true) @SafeVarargs - public final Cffu> cffuAllOf(CompletableFuture... cfs) { + public final Cffu> allResultsOf(CompletableFuture... cfs) { return new0(CompletableFutureUtils.allResultsOf(cfs)); } /** - * Provided this overloaded method just for resolving "cffuAllOf is ambiguous" problem - * when call {@code cffuAllOf} with empty arguments: {@code cffuFactory.cffuAllOf()}. + * Provided this overloaded method just for resolving "allResultsOf is ambiguous" problem + * when call {@code allResultsOf} with empty arguments: {@code cffuFactory.allResultsOf()}. * - * @see #cffuAllOf(Cffu[]) - * @see #cffuAllOf(CompletableFuture[]) + * @see #allResultsOf(Cffu[]) + * @see #allResultsOf(CompletableFuture[]) */ @Contract(pure = true) - public Cffu> cffuAllOf() { + public Cffu> allResultsOf() { return new0(CompletableFutureUtils.allResultsOf()); } @@ -640,13 +640,13 @@ public Cffu> cffuAllOf() { * @return a new CompletableFuture that is successful when all the given CompletableFutures success * @throws NullPointerException if the array or any of its elements are {@code null} * @see CompletableFutureUtils#allOfFastFail(CompletableFuture[]) - * @see #cffuAllOfFastFail(Cffu[]) + * @see #allResultsOfFastFail(Cffu[]) */ @Contract(pure = true) @SafeVarargs @SuppressWarnings({"rawtypes", "unchecked"}) - public final Cffu> cffuAllOfFastFail(Cffu... cfs) { - return cffuAllOfFastFail(toCompletableFutureArray((Cffu[]) cfs)); + public final Cffu> allResultsOfFastFail(Cffu... cfs) { + return allResultsOfFastFail(toCompletableFutureArray((Cffu[]) cfs)); } /** @@ -657,29 +657,29 @@ public final Cffu> cffuAllOfFastFail(Cffu... cfs) { * with a CompletionException holding this exception as its cause. * If no CompletableFutures are provided, returns a Cffu completed with the value empty list. *

    - * Same as {@link #cffuAllOfFastFail(Cffu[])} with overloaded argument type {@link CompletableFuture}. + * Same as {@link #allResultsOfFastFail(Cffu[])} with overloaded argument type {@link CompletableFuture}. * * @param cfs the CompletableFutures * @return a new CompletableFuture that is successful when all the given CompletableFutures success * @throws NullPointerException if the array or any of its elements are {@code null} * @see CompletableFutureUtils#allOfFastFail(CompletableFuture[]) - * @see #cffuAllOfFastFail(Cffu[]) + * @see #allResultsOfFastFail(Cffu[]) */ @Contract(pure = true) @SafeVarargs - public final Cffu> cffuAllOfFastFail(CompletableFuture... cfs) { + public final Cffu> allResultsOfFastFail(CompletableFuture... cfs) { return new0(CompletableFutureUtils.allResultsOfFastFail(cfs)); } /** - * Provided this overloaded method just for resolving "cffuAllOfFastFail is ambiguous" problem - * when call {@code cffuAllOfFastFail} with empty arguments: {@code cffuFactory.cffuAllOfFastFail()}. + * Provided this overloaded method just for resolving "allResultsOfFastFail is ambiguous" problem + * when call {@code allResultsOfFastFail} with empty arguments: {@code cffuFactory.allResultsOfFastFail()}. * - * @see #cffuAllOfFastFail(Cffu[]) - * @see #cffuAllOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(Cffu[]) + * @see #allResultsOfFastFail(CompletableFuture[]) */ @Contract(pure = true) - public Cffu> cffuAllOfFastFail() { + public Cffu> allResultsOfFastFail() { return new0(CompletableFutureUtils.allResultsOfFastFail()); } @@ -693,12 +693,12 @@ public Cffu> cffuAllOfFastFail() { * If any of the given Cffu complete exceptionally, then the returned * Cffu also does so, with a CompletionException holding this exception as its cause. *

    - * Same as {@link #cffuAllOf(Cffu[])} but with two inputs and return results as {@code Tuple2}. + * Same as {@link #allResultsOf(Cffu[])} but with two inputs and return results as {@code Tuple2}. * * @return a new Cffu that is completed when the given two Cffus complete * @throws NullPointerException if any input Cffus are {@code null} * @see Cffu#cffuCombine(Cffu) - * @see #cffuAllOf(Cffu[]) + * @see #allResultsOf(Cffu[]) * @see #allOf(Cffu[]) */ @Contract(pure = true) @@ -717,7 +717,7 @@ public Cffu> cffuCombine(Cffu cf1, Cffu cf2) { * @throws NullPointerException if any of the given CompletableFutures are {@code null} * @see Cffu#cffuCombine(CompletableFuture) * @see #cffuCombine(Cffu, Cffu) - * @see #cffuAllOf(CompletableFuture[]) + * @see #allResultsOf(CompletableFuture[]) * @see #allOf(CompletableFuture[]) */ @Contract(pure = true) @@ -734,7 +734,7 @@ public Cffu> cffuCombine(CompletableFuture cf1, Comp * @return a new Cffu that is successful when the given two Cffus success * @throws NullPointerException if any of the given Cffus are {@code null} * @see Cffu#cffuCombineFastFail(Cffu) - * @see #cffuAllOfFastFail(Cffu[]) + * @see #allResultsOfFastFail(Cffu[]) * @see #allOfFastFail(Cffu[]) */ @Contract(pure = true) @@ -752,7 +752,7 @@ public Cffu> cffuCombineFastFail(Cffu cf1, Cffu * @throws NullPointerException if any of the given CompletableFutures are {@code null} * @see Cffu#cffuCombineFastFail(CompletableFuture) * @see #cffuCombineFastFail(Cffu, Cffu) - * @see #cffuAllOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(CompletableFuture[]) * @see #allOfFastFail(CompletableFuture[]) */ @Contract(pure = true) @@ -765,12 +765,12 @@ public Cffu> cffuCombineFastFail(CompletableFuture c * If any of the given Cffu complete exceptionally, then the returned * Cffu also does so, with a CompletionException holding this exception as its cause. *

    - * Same as {@link #cffuAllOf(Cffu[])} but with three inputs and return results as {@code Tuple3}. + * Same as {@link #allResultsOf(Cffu[])} but with three inputs and return results as {@code Tuple3}. * * @return a new Cffu that is completed when the given three Cffus complete * @throws NullPointerException if any input Cffus are {@code null} * @see Cffu#cffuCombine(Cffu, Cffu) - * @see #cffuAllOf(Cffu[]) + * @see #allResultsOf(Cffu[]) * @see #allOf(Cffu[]) */ @Contract(pure = true) @@ -789,7 +789,7 @@ public Cffu> cffuCombine(Cffu cf1, Cffu * @throws NullPointerException if any of the given CompletableFutures are {@code null} * @see Cffu#cffuCombine(CompletableFuture, CompletableFuture) * @see #cffuCombine(Cffu, Cffu, Cffu) - * @see #cffuAllOf(CompletableFuture[]) + * @see #allResultsOf(CompletableFuture[]) * @see #allOf(CompletableFuture[]) */ @Contract(pure = true) @@ -807,7 +807,7 @@ public Cffu> cffuCombine( * @return a new Cffu that is successful when the given three Cffus success * @throws NullPointerException if any of the given Cffus are {@code null} * @see Cffu#cffuCombineFastFail(Cffu, Cffu) - * @see #cffuAllOfFastFail(Cffu[]) + * @see #allResultsOfFastFail(Cffu[]) * @see #allOfFastFail(Cffu[]) */ @Contract(pure = true) @@ -825,7 +825,7 @@ public Cffu> cffuCombineFastFail(Cffu cf1, C * @throws NullPointerException if any of the given CompletableFutures are {@code null} * @see Cffu#cffuCombineFastFail(CompletableFuture, CompletableFuture) * @see #cffuCombineFastFail(Cffu, Cffu) - * @see #cffuAllOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(CompletableFuture[]) * @see #allOfFastFail(CompletableFuture[]) */ @Contract(pure = true) @@ -839,12 +839,12 @@ public Cffu> cffuCombineFastFail( * If any of the given Cffu complete exceptionally, then the returned * Cffu also does so, with a CompletionException holding this exception as its cause. *

    - * Same as {@link #cffuAllOf(Cffu[])} but with 4 inputs and return results as {@code Tuple4}. + * Same as {@link #allResultsOf(Cffu[])} but with 4 inputs and return results as {@code Tuple4}. * * @return a new Cffu that is completed when the given 4 Cffus complete * @throws NullPointerException if any input Cffus are {@code null} * @see Cffu#cffuCombine(Cffu, Cffu, Cffu) - * @see #cffuAllOf(Cffu[]) + * @see #allResultsOf(Cffu[]) * @see #allOf(Cffu[]) */ @Contract(pure = true) @@ -865,7 +865,7 @@ public Cffu> cffuCombine( * @throws NullPointerException if any of the given CompletableFutures are {@code null} * @see Cffu#cffuCombine(CompletableFuture, CompletableFuture, CompletableFuture) * @see #cffuCombine(Cffu, Cffu, Cffu, Cffu) - * @see #cffuAllOf(CompletableFuture[]) + * @see #allResultsOf(CompletableFuture[]) * @see #allOf(CompletableFuture[]) */ @Contract(pure = true) @@ -885,7 +885,7 @@ public Cffu> cffuCombine( * @return a new Cffu that is successful when the given four Cffus success * @throws NullPointerException if any of the given Cffus are {@code null} * @see Cffu#cffuCombineFastFail(Cffu, Cffu, Cffu) - * @see #cffuAllOfFastFail(Cffu[]) + * @see #allResultsOfFastFail(Cffu[]) * @see #allOfFastFail(Cffu[]) */ @Contract(pure = true) @@ -905,7 +905,7 @@ public Cffu> cffuCombineFastFail( * @throws NullPointerException if any of the given CompletableFutures are {@code null} * @see Cffu#cffuCombineFastFail(CompletableFuture, CompletableFuture, CompletableFuture) * @see #cffuCombineFastFail(Cffu, Cffu) - * @see #cffuAllOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(CompletableFuture[]) * @see #allOfFastFail(CompletableFuture[]) */ @Contract(pure = true) @@ -920,12 +920,12 @@ public Cffu> cffuCombineFastFail( * If any of the given Cffu complete exceptionally, then the returned * Cffu also does so, with a CompletionException holding this exception as its cause. *

    - * Same as {@link #cffuAllOf(Cffu[])} but with 5 inputs and return results as {@code Tuple5}. + * Same as {@link #allResultsOf(Cffu[])} but with 5 inputs and return results as {@code Tuple5}. * * @return a new Cffu that is completed when the given 5 Cffus complete * @throws NullPointerException if any input Cffus are {@code null} * @see Cffu#cffuCombine(Cffu, Cffu, Cffu, Cffu) - * @see #cffuAllOf(Cffu[]) + * @see #allResultsOf(Cffu[]) * @see #allOf(Cffu[]) */ @Contract(pure = true) @@ -947,7 +947,7 @@ public Cffu> cffuCombine( * @throws NullPointerException if any of the given CompletableFutures are {@code null} * @see Cffu#cffuCombine(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) * @see #cffuCombine(Cffu, Cffu, Cffu, Cffu, Cffu) - * @see #cffuAllOf(CompletableFuture[]) + * @see #allResultsOf(CompletableFuture[]) * @see #allOf(CompletableFuture[]) */ @Contract(pure = true) @@ -966,7 +966,7 @@ public Cffu> cffuCombine( * @return a new Cffu that is successful when the given five Cffus success * @throws NullPointerException if any of the given Cffus are {@code null} * @see Cffu#cffuCombineFastFail(Cffu, Cffu, Cffu, Cffu) - * @see #cffuAllOfFastFail(Cffu[]) + * @see #allResultsOfFastFail(Cffu[]) * @see #allOfFastFail(Cffu[]) */ @Contract(pure = true) @@ -986,7 +986,7 @@ public Cffu> cffuCombineFastFail * @throws NullPointerException if any of the given CompletableFutures are {@code null} * @see Cffu#cffuCombineFastFail(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) * @see #cffuCombineFastFail(Cffu, Cffu) - * @see #cffuAllOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(CompletableFuture[]) * @see #allOfFastFail(CompletableFuture[]) */ @Contract(pure = true) 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 e6f6c4e1..2664361a 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java @@ -223,54 +223,54 @@ void test_anyOf_CompletableFuture() throws Exception { //# New type-safe allOf/anyOf Factory Methods // method name prefix with `cffu` // - // - cffuAllOf + // - allResultsOf //////////////////////////////////////////////////////////////////////////////// @Test - void test_cffuAllOf() throws Exception { + void test_allResultsOf() throws Exception { assertEquals(Arrays.asList(n, n + 1), - cffuFactory.cffuAllOf(completedFuture(n), completedFuture(n + 1)).get() + cffuFactory.allResultsOf(completedFuture(n), completedFuture(n + 1)).get() ); assertEquals(Collections.singletonList(n), - cffuFactory.cffuAllOf(completedFuture(n)).get() + cffuFactory.allResultsOf(completedFuture(n)).get() ); assertEquals(Collections.emptyList(), - cffuFactory.cffuAllOf().get() + cffuFactory.allResultsOf().get() ); assertEquals(Arrays.asList(n, n + 1), - cffuFactory.cffuAllOf(cffuFactory.completedFuture(n), cffuFactory.completedFuture(n + 1)).get() + cffuFactory.allResultsOf(cffuFactory.completedFuture(n), cffuFactory.completedFuture(n + 1)).get() ); assertEquals(Collections.singletonList(n), - cffuFactory.cffuAllOf(cffuFactory.completedFuture(n)).get() + cffuFactory.allResultsOf(cffuFactory.completedFuture(n)).get() ); //////////////////////////////////////// assertEquals(Arrays.asList(n, n + 1), - cffuFactory.cffuAllOfFastFail(completedFuture(n), completedFuture(n + 1)).get() + cffuFactory.allResultsOfFastFail(completedFuture(n), completedFuture(n + 1)).get() ); assertEquals(Collections.singletonList(n), - cffuFactory.cffuAllOfFastFail(completedFuture(n)).get() + cffuFactory.allResultsOfFastFail(completedFuture(n)).get() ); assertEquals(Collections.emptyList(), - cffuFactory.cffuAllOfFastFail().get() + cffuFactory.allResultsOfFastFail().get() ); assertEquals(Arrays.asList(n, n + 1), - cffuFactory.cffuAllOfFastFail(cffuFactory.completedFuture(n), cffuFactory.completedFuture(n + 1)).get() + cffuFactory.allResultsOfFastFail(cffuFactory.completedFuture(n), cffuFactory.completedFuture(n + 1)).get() ); assertEquals(Collections.singletonList(n), - cffuFactory.cffuAllOfFastFail(cffuFactory.completedFuture(n)).get() + cffuFactory.allResultsOfFastFail(cffuFactory.completedFuture(n)).get() ); } @Test - void test_cffuAllOf_exceptionally() throws Exception { + void test_allResultsOf_exceptionally() throws Exception { try { - cffuFactory.cffuAllOf( + cffuFactory.allResultsOf( cffuFactory.completedFuture(n), cffuFactory.failedFuture(rte), cffuFactory.completedFuture(s) @@ -282,7 +282,7 @@ void test_cffuAllOf_exceptionally() throws Exception { } try { - cffuFactory.cffuAllOfFastFail( + cffuFactory.allResultsOfFastFail( cffuFactory.completedFuture(n), cffuFactory.failedFuture(rte), cffuFactory.completedFuture(s) diff --git a/cffu-core/src/test/java/io/foldright/demo/AllOfWithResultDemo.java b/cffu-core/src/test/java/io/foldright/demo/AllOfWithResultDemo.java index 93148abe..09056bdb 100644 --- a/cffu-core/src/test/java/io/foldright/demo/AllOfWithResultDemo.java +++ b/cffu-core/src/test/java/io/foldright/demo/AllOfWithResultDemo.java @@ -18,7 +18,7 @@ public class AllOfWithResultDemo { public static void main(String[] args) throws Exception { ////////////////////////////////////////////////// - // CffuFactory#cffuAllOf + // CffuFactory#allResultsOf ////////////////////////////////////////////////// Cffu cffu1 = cffuFactory.completedFuture(21); Cffu cffu2 = cffuFactory.completedFuture(42); @@ -29,8 +29,8 @@ public static void main(String[] args) throws Exception { // the result can be got by input argument `cf1.get()`, but it's cumbersome. // so we can see a lot the util methods to enhance allOf with result in our project. - Cffu> allOfWithResult = cffuFactory.cffuAllOf(cffu1, cffu2); - System.out.println(allOfWithResult.get()); + Cffu> allResults = cffuFactory.allResultsOf(cffu1, cffu2); + System.out.println(allResults.get()); ////////////////////////////////////////////////// // or CompletableFutureUtils#allResultsOf @@ -41,8 +41,8 @@ public static void main(String[] args) throws Exception { CompletableFuture allOf2 = CompletableFuture.allOf(cf1, cf2); // Result type is Void!! - CompletableFuture> allOfWithResult2 = CompletableFutureUtils.allResultsOf(cf1, cf2); - System.out.println(allOfWithResult2.get()); + CompletableFuture> allResults2 = CompletableFutureUtils.allResultsOf(cf1, cf2); + System.out.println(allResults2.get()); //////////////////////////////////////// // cleanup diff --git a/cffu-core/src/test/java/io/foldright/demo/ConcurrencyStrategyDemo.java b/cffu-core/src/test/java/io/foldright/demo/ConcurrencyStrategyDemo.java index 7229e365..ec590a91 100644 --- a/cffu-core/src/test/java/io/foldright/demo/ConcurrencyStrategyDemo.java +++ b/cffu-core/src/test/java/io/foldright/demo/ConcurrencyStrategyDemo.java @@ -18,7 +18,7 @@ public class ConcurrencyStrategyDemo { public static void main(String[] args) throws Exception { //////////////////////////////////////////////////////////////////////// - // CffuFactory#cffuAllOfFastFail / allOfFastFail + // CffuFactory#allResultsOfFastFail / allOfFastFail // CffuFactory#anyOfSuccess //////////////////////////////////////////////////////////////////////// final Cffu successAfterLongTime = cffuFactory.supplyAsync(() -> { @@ -29,7 +29,7 @@ public static void main(String[] args) throws Exception { // Result type is Void! Cffu cffuAll = cffuFactory.allOfFastFail(successAfterLongTime, failed); - Cffu> fastFailed = cffuFactory.cffuAllOfFastFail(successAfterLongTime, failed); + Cffu> fastFailed = cffuFactory.allResultsOfFastFail(successAfterLongTime, failed); // fast failed without waiting successAfterLongTime System.out.println(fastFailed.exceptionNow()); diff --git a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt index 9d2197a6..8d32715f 100644 --- a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt +++ b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt @@ -71,18 +71,18 @@ private const val ERROR_MSG_FOR_ARRAY = "no cffuFactory argument provided when t * If no Cffus are provided, returns a Cffu completed with the value empty list. * * Same as [allOfCffuVoid], but the returned Cffu contains the results of input Cffus. - * Same as [CffuFactory.cffuAllOf], providing this method is convenient for method chaining. + * Same as [CffuFactory.allResultsOf], providing this method is convenient for method chaining. * * If this collection is not empty, `cffuFactory` argument is optional, use the `cffuFactory` of the first cffu element. * If this collection is empty and no`cffuFactory` provided, throw [IllegalArgumentException]. * * @see allOfCffuVoid - * @see CffuFactory.cffuAllOf + * @see CffuFactory.allResultsOf */ fun Collection>.allOfCffu(cffuFactory: CffuFactory = ABSENT): Cffu> { val factory: CffuFactory = if (cffuFactory !== ABSENT) cffuFactory else firstOrNull()?.cffuFactory() ?: throw IllegalArgumentException(ERROR_MSG_FOR_COLL) - return factory.cffuAllOf(*this.toTypedArray()) + return factory.allResultsOf(*this.toTypedArray()) } /** @@ -93,18 +93,18 @@ fun Collection>.allOfCffu(cffuFactory: CffuFactory = ABSENT): Cffu Array>.allOfCffu(cffuFactory: CffuFactory = ABSENT): Cffu> { val factory: CffuFactory = if (cffuFactory !== ABSENT) cffuFactory else firstOrNull()?.cffuFactory() ?: throw IllegalArgumentException(ERROR_MSG_FOR_ARRAY) - return factory.cffuAllOf(*this) + return factory.allResultsOf(*this) } /** @@ -115,14 +115,14 @@ fun Array>.allOfCffu(cffuFactory: CffuFactory = ABSENT): Cffu Collection>.allOfCffu(cffuFactory: CffuFactory): Cffu> = - cffuFactory.cffuAllOf(*this.toTypedArray()) + cffuFactory.allResultsOf(*this.toTypedArray()) /** * Returns a new Cffu with the results in the same order of all the given CompletableFutures, @@ -132,13 +132,13 @@ fun Collection>.allOfCffu(cffuFactory: CffuFactory): Cf * If no CompletableFutures are provided, returns a Cffu completed with the value empty list. * * Same as [allOfCffuVoid], but the returned Cffu contains the results of input CompletableFutures. - * Same as [CffuFactory.cffuAllOf], providing this method is convenient for method chaining. + * Same as [CffuFactory.allResultsOf], providing this method is convenient for method chaining. * * @see allOfCffuVoid - * @see CffuFactory.cffuAllOf + * @see CffuFactory.allResultsOf */ fun Array>.allOfCffu(cffuFactory: CffuFactory): Cffu> = - cffuFactory.cffuAllOf(*this) + cffuFactory.allResultsOf(*this) /** * Returns a new Cffu that is completed when all the given Cffus complete. @@ -227,18 +227,18 @@ fun Array>.allOfCffuVoid(cffuFactory: CffuFactory): Cff * If no CompletableFutures are provided, returns a Cffu completed with the value empty list. * * Same as [allOfFastFailCffuVoid], but the returned Cffu contains the results of input Cffus. - * Same as [CffuFactory.cffuAllOfFastFail], providing this method is convenient for method chaining. + * Same as [CffuFactory.allResultsOfFastFail], providing this method is convenient for method chaining. * * If this collection is not empty, `cffuFactory` argument is optional, use the `cffuFactory` of the first cffu element. * If this collection is empty and no`cffuFactory` provided, throw [IllegalArgumentException]. * * @see allOfFastFailCffuVoid - * @see CffuFactory.cffuAllOfFastFail + * @see CffuFactory.allResultsOfFastFail */ fun Collection>.allOfFastFailCffu(cffuFactory: CffuFactory = ABSENT): Cffu> { val factory: CffuFactory = if (cffuFactory !== ABSENT) cffuFactory else firstOrNull()?.cffuFactory() ?: throw IllegalArgumentException(ERROR_MSG_FOR_COLL) - return factory.cffuAllOfFastFail(*this.toTypedArray()) + return factory.allResultsOfFastFail(*this.toTypedArray()) } /** @@ -250,18 +250,18 @@ fun Collection>.allOfFastFailCffu(cffuFactory: CffuFactory = ABSENT) * If no CompletableFutures are provided, returns a Cffu completed with the value empty list. * * Same as [allOfFastFailCffuVoid], but the returned Cffu contains the results of input Cffus. - * Same as [CffuFactory.cffuAllOfFastFail], providing this method is convenient for method chaining. + * Same as [CffuFactory.allResultsOfFastFail], providing this method is convenient for method chaining. * * If this array is not empty, `cffuFactory` argument is optional, use the `cffuFactory` of the first cffu element. * If this array is empty and no`cffuFactory` provided, throw [IllegalArgumentException]. * * @see allOfFastFailCffuVoid - * @see CffuFactory.cffuAllOfFastFail + * @see CffuFactory.allResultsOfFastFail */ fun Array>.allOfFastFailCffu(cffuFactory: CffuFactory = ABSENT): Cffu> { val factory: CffuFactory = if (cffuFactory !== ABSENT) cffuFactory else firstOrNull()?.cffuFactory() ?: throw IllegalArgumentException(ERROR_MSG_FOR_ARRAY) - return factory.cffuAllOfFastFail(*this) + return factory.allResultsOfFastFail(*this) } /** @@ -273,14 +273,14 @@ fun Array>.allOfFastFailCffu(cffuFactory: CffuFactory = ABSENT): Cff * If no CompletableFutures are provided, returns a Cffu completed with the value empty list. * * Same as [allOfFastFailCffuVoid], but the returned Cffu contains the results of input Cffus. - * Same as [CffuFactory.cffuAllOfFastFail], providing this method is convenient for method chaining. + * Same as [CffuFactory.allResultsOfFastFail], providing this method is convenient for method chaining. * * @see allOfFastFailCffuVoid - * @see CffuFactory.cffuAllOfFastFail + * @see CffuFactory.allResultsOfFastFail */ @JvmName("allOfFastFailCffuCf") fun Collection>.allOfFastFailCffu(cffuFactory: CffuFactory): Cffu> = - cffuFactory.cffuAllOfFastFail(*this.toTypedArray()) + cffuFactory.allResultsOfFastFail(*this.toTypedArray()) /** * Returns a new Cffu with the results in the same order of all the given CompletableFutures, @@ -291,13 +291,13 @@ fun Collection>.allOfFastFailCffu(cffuFactory: CffuFact * If no CompletableFutures are provided, returns a Cffu completed with the value empty list. * * Same as [allOfFastFailCffuVoid], but the returned Cffu contains the results of input Cffus. - * Same as [CffuFactory.cffuAllOfFastFail], providing this method is convenient for method chaining. + * Same as [CffuFactory.allResultsOfFastFail], providing this method is convenient for method chaining. * * @see allOfFastFailCffuVoid - * @see CffuFactory.cffuAllOfFastFail + * @see CffuFactory.allResultsOfFastFail */ fun Array>.allOfFastFailCffu(cffuFactory: CffuFactory): Cffu> = - cffuFactory.cffuAllOfFastFail(*this) + cffuFactory.allResultsOfFastFail(*this) /** * Returns a new Cffu that is successful when all the given Cffus success,