diff --git a/README.md b/README.md index 093c7b9c..2b9f3fb5 100644 --- a/README.md +++ b/README.md @@ -73,15 +73,15 @@ - `cffuAllOf`/`allOfWithResult`方法:返回多个`CF`的结果,而不是无返回结果`Void`(`allOf`) - `cffuCombine`/`combine`方法:返回多个`CF`不同类型的结果,而不是同一类型(`cffuAllOf`/`allOfWithResult`) - 更高效灵活的并发执行策略,如 - - `cffuAllOfFastFail`/`allOfFastFail`方法:有`CF`失败时快速返回,而不再等待所有`CF`运行完成(`allOf`) - - `cffuAnyOfSuccess`/`anyOfSuccess`方法:返回首个成功的`CF`结果,而不是首个完成(但可能失败)的`CF`(`anyOf`) + - `allOfFastFail`方法:有`CF`失败时快速返回,而不再等待所有`CF`运行完成(`allOf`) + - `anyOfSuccess`方法:返回首个成功的`CF`结果,而不是首个完成(但可能失败)的`CF`(`anyOf`) - 更安全的使用方式,如 - 支持设置缺省的业务线程池(`CffuFactoryBuilder#newCffuFactoryBuilder(executor)`方法) - `cffuJoin(timeout, unit)`方法:支持超时的`join`的方法 - 支持禁止强制篡改(`CffuFactoryBuilder#forbidObtrudeMethods`方法) - 在类方法附加完善的代码质量注解(如`@NonNull`、`@Nullable`、`@CheckReturnValue`、`@Contract`等),在编码时`IDE`能尽早提示出问题 - 💪 **已有功能的增强**,如 - - `cffuAnyOf`/`anyOfWithType`方法:返回类型是`T`(类型安全),而不是返回`Object`(`anyOf`) + - `anyOf`方法:返回类型是`T`(类型安全),而不是返回`Object`(`CompletableFuture#anyOf()`) - ⏳ **`Backport`支持`Java 8`**,`Java 9+`高版本的所有`CF`新功能在`Java 8`等低`Java`版本直接可用,如 - 超时控制:`orTimeout`/`completeOnTimeout`方法 - 延迟执行:`delayedExecutor`方法 @@ -182,7 +182,7 @@ public class CffuDemo { final Cffu combined = longTaskA.thenCombine(longTaskB, Integer::sum) .orTimeout(1500, TimeUnit.MILLISECONDS); System.out.println("combined result: " + combined.get()); - final Cffu anyOfSuccess = cffuFactory.cffuAnyOfSuccess(longTaskC, longFailedTask); + final Cffu anyOfSuccess = cffuFactory.anyOfSuccess(longTaskC, longFailedTask); System.out.println("anyOfSuccess result: " + anyOfSuccess.get()); } } @@ -418,7 +418,7 @@ public class DefaultExecutorSettingForCffu { - `allOf`/`allOfFastFail`两者都是,只有当所有的输入`CF`都成功时,才返回成功结果 - `CompletableFuture`的`anyOf`方法返回首个完成的`CF`(不会等待后续没有完成的`CF`,赛马模式);即使首个完成的`CF`是失败的,也会返回这个失败的`CF`结果。 - 对于业务逻辑来说,会希望赛马模式返回首个成功的`CF`结果,而不是首个完成但失败的`CF` - - `cffu`提供了相应的`cffuAnyOfSuccess`/`anyOfSuccess`方法 + - `cffu`提供了相应的`anyOfSuccess`方法 - `anyOfSuccess`只有当所有的输入`CF`都失败时,才返回失败结果 > 📔 关于多个`CF`的并发执行策略,可以看看`JavaScript`规范[`Promise Concurrency`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#promise_concurrency);在`JavaScript`中,`Promise`即对应`CompletableFuture`。 @@ -444,7 +444,7 @@ public class ConcurrencyStrategyDemo { public static void main(String[] args) throws Exception { //////////////////////////////////////////////////////////////////////// // CffuFactory#cffuAllOfFastFail / allOfFastFail - // CffuFactory#cffuAnyOfSuccess / anyOfSuccess + // CffuFactory#anyOfSuccess //////////////////////////////////////////////////////////////////////// final Cffu successAfterLongTime = cffuFactory.supplyAsync(() -> { sleep(3000); // sleep LONG time @@ -461,7 +461,7 @@ public class ConcurrencyStrategyDemo { // Result type is Object! Cffu cffuAny = cffuFactory.anyOfSuccess(successAfterLongTime, failed); System.out.println(cffuAny.get()); - Cffu anyOfSuccess = cffuFactory.cffuAnyOfSuccess(successAfterLongTime, failed); + Cffu anyOfSuccess = cffuFactory.anyOfSuccess(successAfterLongTime, failed); System.out.println(anyOfSuccess.get()); //////////////////////////////////////////////////////////////////////// @@ -519,7 +519,7 @@ public class ConcurrencyStrategyDemo { `CompletableFuture.anyOf`方法返回类型是`Object`,丢失具体类型,不够类型安全,使用时需要转型也不方便。 -`cffu`提供了`cffuAnyOf`/`anyOfWithType`方法,返回类型是`T`(类型安全),而不是返回`Object`(`anyOf`)。 +`cffu`提供了`anyOf`/`anyOf`方法,返回类型是`T`(类型安全),而不是返回`Object`(`CompletableFuture#anyOf()`)。 这个新方法使用简单类似,不附代码示例。 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 c617fbe6..ccb7e86a 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -443,41 +443,35 @@ public Cffu allOfFastFail() { * Otherwise, if it completed exceptionally, the returned Cffu also does so, * with a CompletionException holding this exception as its cause.
* If no Cffus are provided, returns an incomplete Cffu. - *

- * prefer {@link #cffuAnyOf(Cffu[])} method if the given Cffus have same result type, - * because {@link #cffuAnyOf(Cffu[])} return type {@code T} instead of type {@code Object}, more type safe. * * @param cfs the Cffus * @return a new Cffu that is completed with the result * or exception from any of the given Cffus when one completes * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #cffuAnyOf(Cffu[]) * @see CompletableFuture#anyOf(CompletableFuture[]) */ @Contract(pure = true) @SuppressWarnings("unchecked") - public Cffu anyOf(Cffu... cfs) { - return anyOf(toCompletableFutureArray((Cffu[]) cfs)); + @SafeVarargs + public final Cffu anyOf(Cffu... cfs) { + return anyOf(toCompletableFutureArray((Cffu[]) cfs)); } /** * Same as {@link #anyOf(Cffu[])} with overloaded argument type {@link CompletableFuture}. - *

- * prefer {@link #cffuAnyOf(CompletableFuture[])} method if the given Cffus have same result type, - * because {@link #cffuAnyOf(CompletableFuture[])} return type {@code T} - * instead of type {@code Object}, more type safe. * * @param cfs the CompletableFutures * @return a new Cffu that is completed with the result * or exception from any of the given CompletableFutures when one completes * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #cffuAnyOf(CompletableFuture[]) * @see #anyOf(Cffu[]) * @see CompletableFuture#anyOf(CompletableFuture[]) */ @Contract(pure = true) - public Cffu anyOf(CompletableFuture... cfs) { - return new0(CompletableFuture.anyOf(cfs)); + @SuppressWarnings("unchecked") + @SafeVarargs + public final Cffu anyOf(CompletableFuture... cfs) { + return (Cffu) new0(CompletableFuture.anyOf(cfs)); } /** @@ -488,7 +482,7 @@ public Cffu anyOf(CompletableFuture... cfs) { * @see #anyOf(CompletableFuture[]) */ @Contract(pure = true) - public Cffu anyOf() { + public Cffu anyOf() { return newIncompleteCffu(); } @@ -503,11 +497,11 @@ public Cffu anyOf() { * @param cfs the Cffus * @return a new Cffu * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #cffuAnyOf(Cffu[]) */ @SuppressWarnings({"unchecked", "rawtypes"}) - public Cffu anyOfSuccess(Cffu... cfs) { - return anyOfSuccess(toCompletableFutureArray((Cffu[]) cfs)); + @SafeVarargs + public final Cffu anyOfSuccess(Cffu... cfs) { + return (Cffu) anyOfSuccess(toCompletableFutureArray((Cffu[]) cfs)); } /** @@ -521,21 +515,17 @@ public Cffu anyOfSuccess(Cffu... cfs) { * @param cfs the CompletableFutures * @return a new Cffu * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #cffuAnyOfSuccess(Cffu[]) - * @see #cffuAnyOf(Cffu[]) */ - public Cffu anyOfSuccess(CompletableFuture... cfs) { + @SafeVarargs + public final Cffu anyOfSuccess(CompletableFuture... cfs) { return new0(CompletableFutureUtils.anyOfSuccess(cfs)); } /** - * Provided this overloaded method just for resolving "cffuAnyOfSuccess is ambiguous" problem + * Provided this overloaded method just for resolving "anyOfSuccess is ambiguous" problem * when call {@code anyOfSuccess} with empty arguments: {@code cffuFactory.anyOfSuccess()}. - * - * @see #cffuAnyOfSuccess(Cffu[]) - * @see #cffuAnyOfSuccess(CompletableFuture[]) */ - public Cffu anyOfSuccess() { + public Cffu anyOfSuccess() { return new0(CompletableFutureUtils.anyOfSuccess()); } @@ -581,7 +571,6 @@ public Executor delayedExecutor(long delay, TimeUnit unit, Executor executor) { // method name prefix with `cffu` // // - cffuAllOf - // - cffuAnyOf //////////////////////////////////////////////////////////////////////////////// /** @@ -694,104 +683,6 @@ public Cffu> cffuAllOfFastFail() { return new0(CompletableFutureUtils.allResultsOfFastFail()); } - /** - * Returns a new Cffu that is completed when any of the given Cffus complete, with the same result. - *

- * Same as {@link #anyOf(Cffu[])}, but return result type is specified type instead of type {@code Object}. - * - * @param cfs the Cffus - * @return a new Cffu that is completed with the result - * or exception from any of the given Cffus when one completes - * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #anyOf(Cffu[]) - */ - @Contract(pure = true) - @SafeVarargs - @SuppressWarnings({"unchecked", "rawtypes"}) - public final Cffu cffuAnyOf(Cffu... cfs) { - return cffuAnyOf(toCompletableFutureArray((Cffu[]) cfs)); - } - - /** - * Returns a new Cffu that is completed when any of the given CompletableFutures complete, with the same result. - *

- * Same as {@link #cffuAllOf(Cffu[])} with overloaded argument type {@link CompletableFuture}. - * - * @param cfs the CompletableFutures - * @return a new Cffu that is completed with the result - * or exception from any of the given CompletableFutures when one completes - * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #cffuAnyOf(Cffu[]) - */ - @Contract(pure = true) - @SafeVarargs - public final Cffu cffuAnyOf(CompletableFuture... cfs) { - return new0(CompletableFutureUtils.anyOf(cfs)); - } - - /** - * Provided this overloaded method just for resolving "cffuAnyOf is ambiguous" problem - * when call {@code cffuAnyOf} with empty arguments: {@code cffuFactory.cffuAnyOf()}. - * - * @see #cffuAnyOf(Cffu[]) - * @see #cffuAnyOf(CompletableFuture[]) - */ - @Contract(pure = true) - public Cffu cffuAnyOf() { - return newIncompleteCffu(); - } - - /** - * Returns a new Cffu that is successful when any of the given Cffus success, - * with the same result. Otherwise, all the given Cffus complete exceptionally, - * the returned Cffu also does so, with a CompletionException holding - * an exception from any of the given Cffu as its cause. If no Cffu are provided, - * returns a new Cffu that is already completed exceptionally - * with a CompletionException holding a {@link NoCfsProvidedException} as its cause. - * - * @param cfs the Cffus - * @return a new Cffu - * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #cffuAnyOf(Cffu[]) - */ - @SafeVarargs - @SuppressWarnings({"rawtypes", "unchecked"}) - public final Cffu cffuAnyOfSuccess(Cffu... cfs) { - return cffuAnyOfSuccess(toCompletableFutureArray((Cffu[]) cfs)); - } - - /** - * Returns a new Cffu that is successful when any of the given CompletableFutures success, - * with the same result. Otherwise, all the given CompletableFutures complete exceptionally, - * the returned Cffu also does so, with a CompletionException holding - * an exception from any of the given CompletableFutures as its cause. If no CompletableFutures are provided, - * returns a new Cffu that is already completed exceptionally - * with a CompletionException holding a {@link NoCfsProvidedException} as its cause. - *

- * Same as {@link #cffuAnyOfSuccess(Cffu[])} with overloaded argument type {@link CompletableFuture}. - * - * @param cfs the CompletableFutures - * @return a new Cffu - * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #cffuAnyOfSuccess(Cffu[]) - * @see #cffuAnyOf(Cffu[]) - */ - @SafeVarargs - public final Cffu cffuAnyOfSuccess(CompletableFuture... cfs) { - return new0(CompletableFutureUtils.anyOfSuccess(cfs)); - } - - /** - * Provided this overloaded method just for resolving "cffuAnyOfSuccess is ambiguous" problem - * when call {@code cffuAnyOfSuccess} with empty arguments: {@code cffuFactory.cffuAnyOfSuccess()}. - * - * @see #cffuAnyOfSuccess(Cffu[]) - * @see #cffuAnyOfSuccess(CompletableFuture[]) - */ - public Cffu cffuAnyOfSuccess() { - return new0(CompletableFutureUtils.anyOfSuccess()); - } - //////////////////////////////////////////////////////////////////////////////// //# New type-safe cffuCombine Factory Methods // support 2~5 input arguments, method name prefix with `cffu` diff --git a/cffu-core/src/main/java/io/foldright/cffu/NoCfsProvidedException.java b/cffu-core/src/main/java/io/foldright/cffu/NoCfsProvidedException.java index d71656db..4f0ec6de 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/NoCfsProvidedException.java +++ b/cffu-core/src/main/java/io/foldright/cffu/NoCfsProvidedException.java @@ -7,8 +7,6 @@ * Exception indicates that NO cfs({@link Cffu} / {@link CompletableFuture}) are provided * for methods require cf arguments. * - * @see CffuFactory#cffuAnyOfSuccess(Cffu[]) - * @see CffuFactory#cffuAnyOfSuccess(CompletableFuture[]) * @see CffuFactory#anyOfSuccess(Cffu[]) * @see CffuFactory#anyOfSuccess(CompletableFuture[]) * @see CompletableFutureUtils#anyOfSuccess(CompletableFuture[]) 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 75d35b63..e6f6c4e1 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java @@ -224,7 +224,6 @@ void test_anyOf_CompletableFuture() throws Exception { // method name prefix with `cffu` // // - cffuAllOf - // - cffuAnyOf //////////////////////////////////////////////////////////////////////////////// @Test @@ -296,56 +295,56 @@ void test_cffuAllOf_exceptionally() throws Exception { } @Test - void test_cffuAnyOf() throws Exception { - assertEquals(n, cffuFactory.cffuAnyOf( + void test_anyOf() throws Exception { + assertEquals(n, cffuFactory.anyOf( createIncompleteFuture(), completedFuture(n) ).get()); - assertEquals(n, cffuFactory.cffuAnyOf( + assertEquals(n, cffuFactory.anyOf( completedFuture(n) ).get()); - assertFalse(cffuFactory.cffuAnyOf().isDone()); + assertFalse(cffuFactory.anyOf().isDone()); - assertEquals(n, cffuFactory.cffuAnyOf( + assertEquals(n, cffuFactory.anyOf( cffuFactory.completedFuture(n), cffuFactory.newIncompleteCffu() ).get()); - assertEquals(n, cffuFactory.cffuAnyOf( + assertEquals(n, cffuFactory.anyOf( cffuFactory.completedFuture(n) ).get()); //////////////////////////////////////// - assertEquals(n, cffuFactory.cffuAnyOfSuccess(createIncompleteFuture(), completedFuture(n)).get()); - assertEquals(n, cffuFactory.cffuAnyOfSuccess(completedFuture(n)).get()); + assertEquals(n, cffuFactory.anyOfSuccess(createIncompleteFuture(), completedFuture(n)).get()); + assertEquals(n, cffuFactory.anyOfSuccess(completedFuture(n)).get()); - assertSame(NoCfsProvidedException.class, cffuFactory.cffuAnyOfSuccess().exceptionNow().getClass()); + assertSame(NoCfsProvidedException.class, cffuFactory.anyOfSuccess().exceptionNow().getClass()); - assertEquals(n, cffuFactory.cffuAnyOfSuccess( + assertEquals(n, cffuFactory.anyOfSuccess( cffuFactory.completedFuture(n), cffuFactory.newIncompleteCffu() ).get()); - assertEquals(n, cffuFactory.cffuAnyOfSuccess(cffuFactory.completedFuture(n)).get()); + assertEquals(n, cffuFactory.anyOfSuccess(cffuFactory.completedFuture(n)).get()); } @Test - void test_cffuAnyOf_exceptionally() throws Exception { - // first exceptionally completed cffuAnyOf cf win, + void test_anyOf_exceptionally() throws Exception { + // first exceptionally completed anyOf cf win, // even later cfs normally completed! try { - cffuFactory.cffuAnyOf(createIncompleteFuture(), failedFuture(rte), createIncompleteFuture()).get(); + cffuFactory.anyOf(createIncompleteFuture(), failedFuture(rte), createIncompleteFuture()).get(); fail(); } catch (ExecutionException expected) { assertSame(rte, expected.getCause()); } - // first normally completed cffuAnyOf cf win, + // first normally completed anyOf cf win, // even later cfs exceptionally completed! - assertEquals(n, cffuFactory.cffuAnyOf( + assertEquals(n, cffuFactory.anyOf( createIncompleteFuture(), completedFuture(n), createIncompleteFuture() @@ -353,9 +352,9 @@ void test_cffuAnyOf_exceptionally() throws Exception { } @Test - void test_cffuAnyOfSuccess__trivial_case() throws Exception { + void test_anyOfSuccess__trivial_case() throws Exception { // success then success - assertEquals(n, cffuFactory.cffuAnyOfSuccess( + assertEquals(n, cffuFactory.anyOfSuccess( cffuFactory.newIncompleteCffu(), cffuFactory.newIncompleteCffu(), cffuFactory.supplyAsync(() -> { @@ -365,7 +364,7 @@ void test_cffuAnyOfSuccess__trivial_case() throws Exception { cffuFactory.completedFuture(n) ).get()); // success then failed - assertEquals(n, cffuFactory.cffuAnyOfSuccess( + assertEquals(n, cffuFactory.anyOfSuccess( cffuFactory.newIncompleteCffu(), cffuFactory.newIncompleteCffu(), cffuFactory.supplyAsync(() -> { @@ -376,7 +375,7 @@ void test_cffuAnyOfSuccess__trivial_case() throws Exception { ).get()); // all success - assertEquals(n, cffuFactory.cffuAnyOfSuccess( + assertEquals(n, cffuFactory.anyOfSuccess( cffuFactory.supplyAsync(() -> { sleep(300); return anotherN; @@ -391,7 +390,7 @@ void test_cffuAnyOfSuccess__trivial_case() throws Exception { ////////////////////////////////////////////////////////////////////////////// // success then success - assertEquals(n, cffuFactory.cffuAnyOfSuccess( + assertEquals(n, cffuFactory.anyOfSuccess( createIncompleteFuture(), createIncompleteFuture(), CompletableFuture.supplyAsync(() -> { @@ -401,7 +400,7 @@ void test_cffuAnyOfSuccess__trivial_case() throws Exception { completedFuture(n) ).get()); // success then failed - assertEquals(n, cffuFactory.cffuAnyOfSuccess( + assertEquals(n, cffuFactory.anyOfSuccess( createIncompleteFuture(), createIncompleteFuture(), CompletableFuture.supplyAsync(() -> { @@ -412,7 +411,7 @@ void test_cffuAnyOfSuccess__trivial_case() throws Exception { ).get()); // all success - assertEquals(n, cffuFactory.cffuAnyOfSuccess( + assertEquals(n, cffuFactory.anyOfSuccess( CompletableFuture.supplyAsync(() -> { sleep(300); return anotherN; @@ -426,7 +425,7 @@ void test_cffuAnyOfSuccess__trivial_case() throws Exception { ////////////////////////////////////////////////////////////////////////////// - assertSame(NoCfsProvidedException.class, cffuFactory.cffuAnyOfSuccess().exceptionNow().getClass()); + assertSame(NoCfsProvidedException.class, cffuFactory.anyOfSuccess().exceptionNow().getClass()); } //////////////////////////////////////////////////////////////////////////////// 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 eeb07897..7229e365 100644 --- a/cffu-core/src/test/java/io/foldright/demo/ConcurrencyStrategyDemo.java +++ b/cffu-core/src/test/java/io/foldright/demo/ConcurrencyStrategyDemo.java @@ -19,7 +19,7 @@ public class ConcurrencyStrategyDemo { public static void main(String[] args) throws Exception { //////////////////////////////////////////////////////////////////////// // CffuFactory#cffuAllOfFastFail / allOfFastFail - // CffuFactory#cffuAnyOfSuccess / anyOfSuccess + // CffuFactory#anyOfSuccess //////////////////////////////////////////////////////////////////////// final Cffu successAfterLongTime = cffuFactory.supplyAsync(() -> { sleep(3000); // sleep LONG time @@ -33,10 +33,7 @@ public static void main(String[] args) throws Exception { // fast failed without waiting successAfterLongTime System.out.println(fastFailed.exceptionNow()); - // Result type is Object! - Cffu cffuAny = cffuFactory.anyOfSuccess(successAfterLongTime, failed); - System.out.println(cffuAny.get()); - Cffu anyOfSuccess = cffuFactory.cffuAnyOfSuccess(successAfterLongTime, failed); + Cffu anyOfSuccess = cffuFactory.anyOfSuccess(successAfterLongTime, failed); System.out.println(anyOfSuccess.get()); //////////////////////////////////////////////////////////////////////// @@ -55,9 +52,6 @@ public static void main(String[] args) throws Exception { // fast failed without waiting successAfterLongTime System.out.println(CompletableFutureUtils.exceptionNow(fastFailedCf)); - // Result type is Object! - CompletableFuture cfAny = CompletableFutureUtils.anyOfSuccess(successAfterLongTimeCf, failedCf); - System.out.println(cfAny.get()); CompletableFuture cfSuccess = CompletableFutureUtils.anyOfSuccess(successAfterLongTimeCf, failedCf); System.out.println(cfSuccess.get()); 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 fddebfe0..9d2197a6 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 @@ -393,62 +393,62 @@ fun Array>.allOfFastFailCffuVoid(cffuFactory: CffuFacto * Returns a new Cffu that is completed when any of the given Cffus complete, with the same result. * * Same as [anyOfCffuAny], but return result type is specified type instead of type `Any`. - * Same as [CffuFactory.cffuAnyOf], providing this method is convenient for method chaining. + * Same as [CffuFactory.anyOf], 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 anyOfCffuAny - * @see CffuFactory.cffuAnyOf + * @see CffuFactory.anyOf */ fun Collection>.anyOfCffu(cffuFactory: CffuFactory = ABSENT): Cffu { val factory: CffuFactory = if (cffuFactory !== ABSENT) cffuFactory else firstOrNull()?.cffuFactory() ?: throw IllegalArgumentException(ERROR_MSG_FOR_COLL) - return factory.cffuAnyOf(*this.toTypedArray()) + return factory.anyOf(*this.toTypedArray()) } /** * Returns a new Cffu that is completed when any of the given Cffus complete, with the same result. * * Same as [anyOfCffuAny], but return result type is specified type instead of type `Any`. - * Same as [CffuFactory.cffuAnyOf], providing this method is convenient for method chaining. + * Same as [CffuFactory.anyOf], 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 anyOfCffuAny - * @see CffuFactory.cffuAnyOf + * @see CffuFactory.anyOf */ fun Array>.anyOfCffu(cffuFactory: CffuFactory = ABSENT): Cffu { val factory: CffuFactory = if (cffuFactory !== ABSENT) cffuFactory else firstOrNull()?.cffuFactory() ?: throw IllegalArgumentException(ERROR_MSG_FOR_ARRAY) - return factory.cffuAnyOf(*this) + return factory.anyOf(*this) } /** * Returns a new Cffu that is completed when any of the given CompletableFutures complete, with the same result. * * Same as [anyOfCffuAny], but return result type is specified type instead of type `Any`. - * Same as [CffuFactory.cffuAnyOf], providing this method is convenient for method chaining. + * Same as [CffuFactory.anyOf], providing this method is convenient for method chaining. * * @see anyOfCffuAny - * @see CffuFactory.cffuAnyOf + * @see CffuFactory.anyOf */ @JvmName("anyOfCffuCf") fun Collection>.anyOfCffu(cffuFactory: CffuFactory): Cffu = - cffuFactory.cffuAnyOf(*this.toTypedArray()) + cffuFactory.anyOf(*this.toTypedArray()) /** * Returns a new Cffu that is completed when any of the given CompletableFutures complete, with the same result. * * Same as [anyOfCffuAny], but return result type is specified type instead of type `Any`. - * Same as [CffuFactory.cffuAnyOf], providing this method is convenient for method chaining. + * Same as [CffuFactory.anyOf], providing this method is convenient for method chaining. * * @see anyOfCffuAny - * @see CffuFactory.cffuAnyOf + * @see CffuFactory.anyOf */ fun Array>.anyOfCffu(cffuFactory: CffuFactory): Cffu = - cffuFactory.cffuAnyOf(*this) + cffuFactory.anyOf(*this) /** * Returns a new Cffu that is completed when any of the given Cffus complete, with the same result. @@ -515,18 +515,18 @@ fun Array>.anyOfCffuAny(cffuFactory: CffuFactory): Cffu * returns a new Cffu that is already completed exceptionally with a CompletionException * holding a [NoCfsProvidedException][io.foldright.cffu.NoCfsProvidedException] as its cause. * - * Same as [CffuFactory.cffuAnyOfSuccess], providing this method is convenient for method chaining. + * Same as [CffuFactory.anyOfSuccess], 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 anyOfCffu - * @see CffuFactory.cffuAnyOfSuccess + * @see CffuFactory.anyOfSuccess */ fun Collection>.anyOfSuccessCffu(cffuFactory: CffuFactory = ABSENT): Cffu { val factory: CffuFactory = if (cffuFactory !== ABSENT) cffuFactory else firstOrNull()?.cffuFactory() ?: throw IllegalArgumentException(ERROR_MSG_FOR_COLL) - return factory.cffuAnyOfSuccess(*this.toTypedArray()) + return factory.anyOfSuccess(*this.toTypedArray()) } /** @@ -537,18 +537,18 @@ fun Collection>.anyOfSuccessCffu(cffuFactory: CffuFactory = ABSENT): * returns a new Cffu that is already completed exceptionally with a CompletionException * holding a [NoCfsProvidedException][io.foldright.cffu.NoCfsProvidedException] as its cause. * - * Same as [CffuFactory.cffuAnyOfSuccess], providing this method is convenient for method chaining. + * Same as [CffuFactory.anyOfSuccess], 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 anyOfCffu - * @see CffuFactory.cffuAnyOfSuccess + * @see CffuFactory.anyOfSuccess */ fun Array>.anyOfSuccessCffu(cffuFactory: CffuFactory = ABSENT): Cffu { val factory: CffuFactory = if (cffuFactory !== ABSENT) cffuFactory else firstOrNull()?.cffuFactory() ?: throw IllegalArgumentException(ERROR_MSG_FOR_ARRAY) - return factory.cffuAnyOfSuccess(*this) + return factory.anyOfSuccess(*this) } /** @@ -559,14 +559,14 @@ fun Array>.anyOfSuccessCffu(cffuFactory: CffuFactory = ABSENT): Cffu * returns a new Cffu that is already completed exceptionally with a CompletionException * holding a [NoCfsProvidedException][io.foldright.cffu.NoCfsProvidedException] as its cause. * - * Same as [CffuFactory.cffuAnyOfSuccess], providing this method is convenient for method chaining. + * Same as [CffuFactory.anyOfSuccess], providing this method is convenient for method chaining. * * @see anyOfCffu - * @see CffuFactory.cffuAnyOfSuccess + * @see CffuFactory.anyOfSuccess */ @JvmName("anyOfSuccessCffuCf") fun Collection>.anyOfSuccessCffu(cffuFactory: CffuFactory): Cffu = - cffuFactory.cffuAnyOfSuccess(*this.toTypedArray()) + cffuFactory.anyOfSuccess(*this.toTypedArray()) /** * Returns a new Cffu that is successful when any of the given CompletableFutures success, @@ -576,13 +576,13 @@ fun Collection>.anyOfSuccessCffu(cffuFactory: CffuFacto * returns a new Cffu that is already completed exceptionally with a CompletionException * holding a [NoCfsProvidedException][io.foldright.cffu.NoCfsProvidedException] as its cause. * - * Same as [CffuFactory.cffuAnyOfSuccess], providing this method is convenient for method chaining. + * Same as [CffuFactory.anyOfSuccess], providing this method is convenient for method chaining. * * @see anyOfCffu - * @see CffuFactory.cffuAnyOfSuccess + * @see CffuFactory.anyOfSuccess */ fun Array>.anyOfSuccessCffu(cffuFactory: CffuFactory): Cffu = - cffuFactory.cffuAnyOfSuccess(*this) + cffuFactory.anyOfSuccess(*this) /** * Returns a new Cffu that is successful when any of the given CompletableFutures success, @@ -668,7 +668,7 @@ fun Array>.anyOfSuccessCffuAny(cffuFactory: CffuFactory /** * Convert [Cffu] collection elements to [CompletableFuture] by [Cffu.toCompletableFuture]. * - * Same as [CffuFactory.cffuAnyOf], providing this method is convenient for method chaining. + * Same as [CffuFactory.anyOf], providing this method is convenient for method chaining. * * @see CffuFactory.toCompletableFutureArray */ @@ -678,7 +678,7 @@ fun Collection>.toCompletableFuture(): List combined = longTaskA.thenCombine(longTaskB, Integer::sum) .orTimeout(1500, TimeUnit.MILLISECONDS); System.out.println("combined result: " + combined.get()); - final Cffu anyOfSuccess = cffuFactory.cffuAnyOfSuccess(longTaskC, longFailedTask); + final Cffu anyOfSuccess = cffuFactory.anyOfSuccess(longTaskC, longFailedTask); System.out.println("anyOfSuccess result: " + anyOfSuccess.get()); ////////////////////////////////////////