diff --git a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java index c392abac..5d4e5afc 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -1947,9 +1947,9 @@ public static CompletableFuture> thenTupleMAp * @return the new CompletableFuture */ public static CompletableFuture> thenTupleMApplyFastFailAsync( - CompletableFuture cfThis, Function fn1, - Function fn2, Function fn3, - Function fn4) { + CompletableFuture cfThis, + Function fn1, Function fn2, + Function fn3, Function fn4) { return thenTupleMApplyFastFailAsync(cfThis, AsyncPoolHolder.ASYNC_POOL, fn1, fn2, fn3, fn4); } @@ -1963,9 +1963,9 @@ public static CompletableFuture> then * @return the new CompletableFuture */ public static CompletableFuture> thenTupleMApplyFastFailAsync( - CompletableFuture cfThis, Executor executor, Function fn1, - Function fn2, Function fn3, - Function fn4) { + CompletableFuture cfThis, Executor executor, + Function fn1, Function fn2, + Function fn3, Function fn4) { requireNonNull(cfThis, "cfThis is null"); requireNonNull(executor, "executor is null"); Function[] fns = requireArrayAndEleNonNull("fn", fn1, fn2, fn3, fn4); @@ -2709,8 +2709,8 @@ public static CompletableFuture runAfterEitherSuccessAsync( * @return the new CompletableFuture */ public static > - C exceptionallyAsync(C cf, Function fn) { - return exceptionallyAsync(cf, fn, AsyncPoolHolder.ASYNC_POOL); + C exceptionallyAsync(C cfThis, Function fn) { + return exceptionallyAsync(cfThis, fn, AsyncPoolHolder.ASYNC_POOL); } /** @@ -2725,16 +2725,16 @@ C exceptionallyAsync(C cf, Function fn) { */ @SuppressWarnings("unchecked") public static > - C exceptionallyAsync(C cf, Function fn, Executor executor) { - requireNonNull(cf, "cf is null"); + C exceptionallyAsync(C cfThis, Function fn, Executor executor) { + requireNonNull(cfThis, "cf is null"); requireNonNull(fn, "fn is null"); requireNonNull(executor, "executor is null"); if (IS_JAVA12_PLUS) { - return (C) cf.exceptionallyAsync(fn, executor); + return (C) cfThis.exceptionallyAsync(fn, executor); } // below code is copied from CompletionStage#exceptionallyAsync - return (C) cf.handle((r, ex) -> (ex == null) ? cf : - cf.handleAsync((r1, ex1) -> fn.apply(ex1), executor) + return (C) cfThis.handle((r, ex) -> (ex == null) ? cfThis : + cfThis.handleAsync((r1, ex1) -> fn.apply(ex1), executor) ).thenCompose(x -> x); } @@ -2754,8 +2754,8 @@ C exceptionallyAsync(C cf, Function fn, Executor executo * @return the new CompletableFuture * @see #cffuOrTimeout(CompletableFuture, Executor, long, TimeUnit) */ - public static > C cffuOrTimeout(C cf, long timeout, TimeUnit unit) { - return cffuOrTimeout(cf, AsyncPoolHolder.ASYNC_POOL, timeout, unit); + public static > C cffuOrTimeout(C cfThis, long timeout, TimeUnit unit) { + return cffuOrTimeout(cfThis, AsyncPoolHolder.ASYNC_POOL, timeout, unit); } /** @@ -2768,12 +2768,12 @@ public static > C cffuOrTimeout(C cf, long timeou * @return the new CompletableFuture */ public static > C cffuOrTimeout( - C cf, Executor executorWhenTimeout, long timeout, TimeUnit unit) { - requireNonNull(cf, "cf is null"); + C cfThis, Executor executorWhenTimeout, long timeout, TimeUnit unit) { + requireNonNull(cfThis, "cf is null"); requireNonNull(executorWhenTimeout, "executorWhenTimeout is null"); requireNonNull(unit, "unit is null"); - return hopExecutorIfAtCfDelayerThread(orTimeout(cf, timeout, unit), executorWhenTimeout); + return hopExecutorIfAtCfDelayerThread(orTimeout(cfThis, timeout, unit), executorWhenTimeout); } /** @@ -2801,20 +2801,20 @@ public static > C cffuOrTimeout( * @return the given CompletableFuture * @see #cffuOrTimeout(CompletableFuture, long, TimeUnit) */ - public static > C orTimeout(C cf, long timeout, TimeUnit unit) { - requireNonNull(cf, "cf is null"); + public static > C orTimeout(C cfThis, long timeout, TimeUnit unit) { + requireNonNull(cfThis, "cf is null"); requireNonNull(unit, "unit is null"); // NOTE: No need check minimal stage, since checked at cf.orTimeout() / cf.isDone() if (IS_JAVA9_PLUS) { - cf.orTimeout(timeout, unit); + cfThis.orTimeout(timeout, unit); } else { // below code is copied from CompletableFuture#orTimeout with small adoption - if (!cf.isDone()) { - ScheduledFuture f = Delayer.delayToTimoutCf(cf, timeout, unit); - cf.whenComplete(new FutureCanceller(f)); + if (!cfThis.isDone()) { + ScheduledFuture f = Delayer.delayToTimoutCf(cfThis, timeout, unit); + cfThis.whenComplete(new FutureCanceller(f)); } } - return cf; + return cfThis; } /** @@ -2829,8 +2829,8 @@ public static > C orTimeout(C cf, long timeout, T * @see #cffuCompleteOnTimeout(CompletableFuture, Object, Executor, long, TimeUnit) */ public static > - C cffuCompleteOnTimeout(C cf, @Nullable T value, long timeout, TimeUnit unit) { - return cffuCompleteOnTimeout(cf, value, AsyncPoolHolder.ASYNC_POOL, timeout, unit); + C cffuCompleteOnTimeout(C cfThis, @Nullable T value, long timeout, TimeUnit unit) { + return cffuCompleteOnTimeout(cfThis, value, AsyncPoolHolder.ASYNC_POOL, timeout, unit); } /** @@ -2843,12 +2843,12 @@ C cffuCompleteOnTimeout(C cf, @Nullable T value, long timeout, TimeUnit unit) { * @return the new CompletableFuture */ public static > - C cffuCompleteOnTimeout(C cf, @Nullable T value, Executor executorWhenTimeout, long timeout, TimeUnit unit) { - requireNonNull(cf, "cf is null"); + C cffuCompleteOnTimeout(C cfThis, @Nullable T value, Executor executorWhenTimeout, long timeout, TimeUnit unit) { + requireNonNull(cfThis, "cf is null"); requireNonNull(executorWhenTimeout, "executorWhenTimeout is null"); requireNonNull(unit, "unit is null"); - return hopExecutorIfAtCfDelayerThread(completeOnTimeout(cf, value, timeout, unit), executorWhenTimeout); + return hopExecutorIfAtCfDelayerThread(completeOnTimeout(cfThis, value, timeout, unit), executorWhenTimeout); } /** @@ -2877,20 +2877,20 @@ C cffuCompleteOnTimeout(C cf, @Nullable T value, Executor executorWhenTimeout, l * @see #cffuCompleteOnTimeout(CompletableFuture, Object, long, TimeUnit) */ public static > - C completeOnTimeout(C cf, @Nullable T value, long timeout, TimeUnit unit) { - requireNonNull(cf, "cf is null"); + C completeOnTimeout(C cfThis, @Nullable T value, long timeout, TimeUnit unit) { + requireNonNull(cfThis, "cf is null"); requireNonNull(unit, "unit is null"); // NOTE: No need check minimal stage, since checked at cf.completeOnTimeout() / cf.isDone() if (IS_JAVA9_PLUS) { - cf.completeOnTimeout(value, timeout, unit); + cfThis.completeOnTimeout(value, timeout, unit); } else { // below code is copied from CompletableFuture#completeOnTimeout with small adoption - if (!cf.isDone()) { - ScheduledFuture f = Delayer.delayToCompleteCf(cf, value, timeout, unit); - cf.whenComplete(new FutureCanceller(f)); + if (!cfThis.isDone()) { + ScheduledFuture f = Delayer.delayToCompleteCf(cfThis, value, timeout, unit); + cfThis.whenComplete(new FutureCanceller(f)); } } - return cf; + return cfThis; } @SuppressWarnings("unchecked") @@ -2952,14 +2952,14 @@ private static T reportException(String msg, Throwable ex) { */ @SuppressWarnings({"unchecked", "rawtypes"}) public static > - C exceptionallyCompose(C cf, Function> fn) { - requireNonNull(cf, "cf is null"); + C exceptionallyCompose(C cfThis, Function> fn) { + requireNonNull(cfThis, "cf is null"); requireNonNull(fn, "fn is null"); if (IS_JAVA12_PLUS) { - return (C) cf.exceptionallyCompose((Function) fn); + return (C) cfThis.exceptionallyCompose((Function) fn); } // below code is copied from CompletionStage.exceptionallyCompose - return (C) cf.handle((r, ex) -> (ex == null) ? cf : fn.apply(ex)).thenCompose(x -> x); + return (C) cfThis.handle((r, ex) -> (ex == null) ? cfThis : fn.apply(ex)).thenCompose(x -> x); } /** @@ -2972,8 +2972,8 @@ C exceptionallyCompose(C cf, Function> f * @return the new CompletableFuture */ public static > - C exceptionallyComposeAsync(C cf, Function> fn) { - return exceptionallyComposeAsync(cf, fn, AsyncPoolHolder.ASYNC_POOL); + C exceptionallyComposeAsync(C cfThis, Function> fn) { + return exceptionallyComposeAsync(cfThis, fn, AsyncPoolHolder.ASYNC_POOL); } /** @@ -2987,16 +2987,16 @@ C exceptionallyComposeAsync(C cf, Function> - C exceptionallyComposeAsync(C cf, Function> fn, Executor executor) { - requireNonNull(cf, "cf is null"); + C exceptionallyComposeAsync(C cfThis, Function> fn, Executor executor) { + requireNonNull(cfThis, "cf is null"); requireNonNull(fn, "fn is null"); requireNonNull(executor, "executor is null"); if (IS_JAVA12_PLUS) { - return (C) cf.exceptionallyComposeAsync((Function) fn, executor); + return (C) cfThis.exceptionallyComposeAsync((Function) fn, executor); } // below code is copied from CompletionStage.exceptionallyComposeAsync - return (C) cf.handle((r, ex) -> (ex == null) ? cf : - cf.handleAsync((r1, ex1) -> fn.apply(ex1), executor).thenCompose(x -> x) + return (C) cfThis.handle((r, ex) -> (ex == null) ? cfThis : + cfThis.handleAsync((r1, ex1) -> fn.apply(ex1), executor).thenCompose(x -> x) ).thenCompose(x -> x); } @@ -3017,12 +3017,12 @@ C exceptionallyComposeAsync(C cf, Function> - C peek(C cf, BiConsumer action) { - requireNonNull(cf, "cf is null"); + C peek(C cfThis, BiConsumer action) { + requireNonNull(cfThis, "cf is null"); requireNonNull(action, "action is null"); - cf.whenComplete(action).exceptionally(ex -> reportException("Exception occurred in the action of peek:", ex)); - return cf; + cfThis.whenComplete(action).exceptionally(ex -> reportException("Exception occurred in the action of peek:", ex)); + return cfThis; } /** @@ -3044,8 +3044,8 @@ C peek(C cf, BiConsumer action) { * @see java.util.stream.Stream#peek(Consumer) */ public static > - C peekAsync(C cf, BiConsumer action) { - return peekAsync(cf, action, AsyncPoolHolder.ASYNC_POOL); + C peekAsync(C cfThis, BiConsumer action) { + return peekAsync(cfThis, action, AsyncPoolHolder.ASYNC_POOL); } /** @@ -3066,14 +3066,14 @@ C peekAsync(C cf, BiConsumer action) { * @see java.util.stream.Stream#peek(Consumer) */ public static > - C peekAsync(C cf, BiConsumer action, Executor executor) { - requireNonNull(cf, "cf is null"); + C peekAsync(C cfThis, BiConsumer action, Executor executor) { + requireNonNull(cfThis, "cf is null"); requireNonNull(action, "action is null"); requireNonNull(executor, "executor is null"); - cf.whenCompleteAsync(action, executor).exceptionally(ex -> + cfThis.whenCompleteAsync(action, executor).exceptionally(ex -> reportException("Exception occurred in the action of peekAsync:", ex)); - return cf; + return cfThis; } // endregion @@ -3291,8 +3291,8 @@ public static CffuState state(Future cfThis) { * @return the given CompletableFuture * @see CompletableFuture#completeAsync(Supplier) */ - public static > C completeAsync(C cf, Supplier supplier) { - return completeAsync(cf, supplier, AsyncPoolHolder.ASYNC_POOL); + public static > C completeAsync(C cfThis, Supplier supplier) { + return completeAsync(cfThis, supplier, AsyncPoolHolder.ASYNC_POOL); } /** @@ -3305,19 +3305,19 @@ public static > C completeAsync(C cf, * @see CompletableFuture#completeAsync(Supplier, Executor) */ public static > - C completeAsync(C cf, Supplier supplier, Executor executor) { - requireNonNull(cf, "cf is null"); + C completeAsync(C cfThis, Supplier supplier, Executor executor) { + requireNonNull(cfThis, "cf is null"); requireNonNull(supplier, "supplier is null"); requireNonNull(executor, "executor is null"); if (IS_JAVA9_PLUS) { - cf.completeAsync(supplier, executor); + cfThis.completeAsync(supplier, executor); } else { // NOTE: No need check minimal stage, because on Java 8(not Java 9+) NOT support minimal stage // below code is copied from CompletableFuture#completeAsync with small adoption - executor.execute(new CfCompleterBySupplier<>(cf, supplier)); + executor.execute(new CfCompleterBySupplier<>(cfThis, supplier)); } - return cf; + return cfThis; } /** @@ -3329,8 +3329,8 @@ C completeAsync(C cf, Supplier supplier, Executor executor) { * @see CompletableFuture#completeExceptionally(Throwable) */ public static > - C completeExceptionallyAsync(C cf, Supplier supplier) { - return completeExceptionallyAsync(cf, supplier, AsyncPoolHolder.ASYNC_POOL); + C completeExceptionallyAsync(C cfThis, Supplier supplier) { + return completeExceptionallyAsync(cfThis, supplier, AsyncPoolHolder.ASYNC_POOL); } /** @@ -3343,14 +3343,14 @@ C completeExceptionallyAsync(C cf, Supplier supplier) { * @see CompletableFuture#completeExceptionally(Throwable) */ public static > - C completeExceptionallyAsync(C cf, Supplier supplier, Executor executor) { - requireNonNull(cf, "cf is null"); + C completeExceptionallyAsync(C cfThis, Supplier supplier, Executor executor) { + requireNonNull(cfThis, "cf is null"); requireNonNull(supplier, "supplier is null"); requireNonNull(executor, "executor is null"); - if (isMinStageCf(cf)) throw new UnsupportedOperationException(); + if (isMinStageCf(cfThis)) throw new UnsupportedOperationException(); - executor.execute(new CfExCompleterBySupplier(cf, supplier)); - return cf; + executor.execute(new CfExCompleterBySupplier(cfThis, supplier)); + return cfThis; } // endregion