Skip to content

Commit

Permalink
refactor: adjust executor parameter position with more consistent rul…
Browse files Browse the repository at this point in the history
…e: 🪑

- first parameter(except CfThis) for vararg methods
  - `mSupplyAllSuccessAsync`
  - `mSupplyMostSuccessAsync`
  - `mostSuccessResultsOf`
  - `thenMApplyAllSuccessAsync`
  - `thenMApplyMostSuccessAsync`
- last parameter for non-vararg methods
  - `cffuOrTimeout`
  - `cffuCompleteOnTimeout`
  • Loading branch information
oldratlee committed Nov 30, 2024
1 parent b345257 commit fc1761c
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 162 deletions.
48 changes: 24 additions & 24 deletions cffu-core/src/main/java/io/foldright/cffu/Cffu.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public final <U> Cffu<List<U>> thenMApplyFailFastAsync(Executor executor, Functi
@SafeVarargs
public final <U> Cffu<List<U>> thenMApplyAllSuccessAsync(
@Nullable U valueIfFailed, Function<? super T, ? extends U>... fns) {
return thenMApplyAllSuccessAsync(valueIfFailed, fac.defaultExecutor(), fns);
return thenMApplyAllSuccessAsync(fac.defaultExecutor(), valueIfFailed, fns);
}

/**
Expand All @@ -264,8 +264,8 @@ public final <U> Cffu<List<U>> thenMApplyAllSuccessAsync(
*/
@SafeVarargs
public final <U> Cffu<List<U>> thenMApplyAllSuccessAsync(
@Nullable U valueIfFailed, Executor executor, Function<? super T, ? extends U>... fns) {
return resetCf(CompletableFutureUtils.thenMApplyAllSuccessAsync(cf, valueIfFailed, executor, fns));
Executor executor, @Nullable U valueIfFailed, Function<? super T, ? extends U>... fns) {
return resetCf(CompletableFutureUtils.thenMApplyAllSuccessAsync(cf, executor, valueIfFailed, fns));
}

/**
Expand All @@ -278,7 +278,7 @@ public final <U> Cffu<List<U>> thenMApplyAllSuccessAsync(
@SafeVarargs
public final <U> Cffu<List<U>> thenMApplyMostSuccessAsync(
@Nullable U valueIfNotSuccess, long timeout, TimeUnit unit, Function<? super T, ? extends U>... fns) {
return thenMApplyMostSuccessAsync(valueIfNotSuccess, fac.defaultExecutor(), timeout, unit, fns);
return thenMApplyMostSuccessAsync(fac.defaultExecutor(), valueIfNotSuccess, timeout, unit, fns);
}

/**
Expand All @@ -290,9 +290,9 @@ public final <U> Cffu<List<U>> thenMApplyMostSuccessAsync(
*/
@SafeVarargs
public final <U> Cffu<List<U>> thenMApplyMostSuccessAsync(
@Nullable U valueIfNotSuccess, Executor executor, long timeout, TimeUnit unit,
Executor executor, @Nullable U valueIfNotSuccess, long timeout, TimeUnit unit,
Function<? super T, ? extends U>... fns) {
return resetCf(CompletableFutureUtils.thenMApplyMostSuccessAsync(cf, valueIfNotSuccess, executor, timeout, unit, fns));
return resetCf(CompletableFutureUtils.thenMApplyMostSuccessAsync(cf, executor, valueIfNotSuccess, timeout, unit, fns));
}

/**
Expand Down Expand Up @@ -673,7 +673,7 @@ public <U1, U2> Cffu<Tuple2<U1, U2>> thenMApplyAllSuccessTupleAsync(
}

/**
* Tuple variance of {@link #thenMApplyAllSuccessAsync(Object, Executor, Function[])} with {@code null} valueIfFailed.
* Tuple variance of {@link #thenMApplyAllSuccessAsync(Executor, Object, Function[])} with {@code null} valueIfFailed.
* <p>
* If any of the provided functions fails, its corresponding position will contain {@code null}
* (which is indistinguishable from the function having a successful value of {@code null}).
Expand All @@ -696,7 +696,7 @@ public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenMApplyAllSuccessTupleAsync(
}

/**
* Tuple variance of {@link #thenMApplyAllSuccessAsync(Object, Executor, Function[])} with {@code null} valueIfFailed.
* Tuple variance of {@link #thenMApplyAllSuccessAsync(Executor, Object, Function[])} with {@code null} valueIfFailed.
* <p>
* If any of the provided functions fails, its corresponding position will contain {@code null}
* (which is indistinguishable from the function having a successful value of {@code null}).
Expand All @@ -720,7 +720,7 @@ public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenMApplyAllSuccessTupleAs
}

/**
* Tuple variance of {@link #thenMApplyAllSuccessAsync(Object, Executor, Function[])} with {@code null} valueIfFailed.
* Tuple variance of {@link #thenMApplyAllSuccessAsync(Executor, Object, Function[])} with {@code null} valueIfFailed.
* <p>
* If any of the provided functions fails, its corresponding position will contain {@code null}
* (which is indistinguishable from the function having a successful value of {@code null}).
Expand All @@ -745,7 +745,7 @@ public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenMApplyAllSucces
}

/**
* Tuple variance of {@link #thenMApplyAllSuccessAsync(Object, Executor, Function[])} with {@code null} valueIfFailed.
* Tuple variance of {@link #thenMApplyAllSuccessAsync(Executor, Object, Function[])} with {@code null} valueIfFailed.
* <p>
* If any of the provided functions fails, its corresponding position will contain {@code null}
* (which is indistinguishable from the function having a successful value of {@code null}).
Expand All @@ -770,7 +770,7 @@ public <U1, U2> Cffu<Tuple2<U1, U2>> thenMApplyMostSuccessTupleAsync(
}

/**
* Tuple variance of {@link #thenMApplyMostSuccessAsync(Object, Executor, long, TimeUnit, Function[])}
* Tuple variance of {@link #thenMApplyMostSuccessAsync(Executor, Object, long, TimeUnit, Function[])}
* with {@code null} valueIfNotSuccess.
* <p>
* If any of the provided suppliers is not completed normally, its corresponding position will contain {@code null}
Expand All @@ -796,7 +796,7 @@ public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenMApplyMostSuccessTupleAsync(
}

/**
* Tuple variance of {@link #thenMApplyMostSuccessAsync(Object, Executor, long, TimeUnit, Function[])}
* Tuple variance of {@link #thenMApplyMostSuccessAsync(Executor, Object, long, TimeUnit, Function[])}
* with {@code null} valueIfNotSuccess.
* <p>
* If any of the provided suppliers is not completed normally, its corresponding position will contain {@code null}
Expand All @@ -823,7 +823,7 @@ public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenMApplyMostSuccessTupleA
}

/**
* Tuple variance of {@link #thenMApplyMostSuccessAsync(Object, Executor, long, TimeUnit, Function[])}
* Tuple variance of {@link #thenMApplyMostSuccessAsync(Executor, Object, long, TimeUnit, Function[])}
* with {@code null} valueIfNotSuccess.
* <p>
* If any of the provided suppliers is not completed normally, its corresponding position will contain {@code null}
Expand Down Expand Up @@ -851,7 +851,7 @@ public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenMApplyMostSucce
}

/**
* Tuple variance of {@link #thenMApplyMostSuccessAsync(Object, Executor, long, TimeUnit, Function[])}
* Tuple variance of {@link #thenMApplyMostSuccessAsync(Executor, Object, long, TimeUnit, Function[])}
* with {@code null} valueIfNotSuccess.
* <p>
* If any of the provided suppliers is not completed normally, its corresponding position will contain {@code null}
Expand Down Expand Up @@ -1641,10 +1641,10 @@ public Cffu<T> exceptionallyAsync(Function<Throwable, ? extends T> fn, Executor
*
* @param timeout how long to wait before completing exceptionally with a TimeoutException, in units of {@code unit}
* @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter
* @see #orTimeout(Executor, long, TimeUnit)
* @see #orTimeout(long, TimeUnit, Executor)
*/
public Cffu<T> orTimeout(long timeout, TimeUnit unit) {
return orTimeout(fac.defaultExecutor(), timeout, unit);
return orTimeout(timeout, unit, fac.defaultExecutor());
}

/**
Expand All @@ -1659,14 +1659,14 @@ public Cffu<T> orTimeout(long timeout, TimeUnit unit) {
* "https://github.com/foldright/cffu/blob/main/cffu-core/src/test/java/io/foldright/demo/CfDelayDysfunctionDemo.java"
* >DelayDysfunctionDemo</a>.
*
* @param executorWhenTimeout the async executor when triggered by timeout
* @param timeout how long to wait before completing exceptionally with a TimeoutException,
* in units of {@code unit}
* @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter
* @param executorWhenTimeout the async executor when triggered by timeout
*/
public Cffu<T> orTimeout(Executor executorWhenTimeout, long timeout, TimeUnit unit) {
public Cffu<T> orTimeout(long timeout, TimeUnit unit, Executor executorWhenTimeout) {
checkMinimalStage();
return resetCf(CompletableFutureUtils.cffuOrTimeout(cf, executorWhenTimeout, timeout, unit));
return resetCf(CompletableFutureUtils.cffuOrTimeout(cf, timeout, unit, executorWhenTimeout));
}

/**
Expand Down Expand Up @@ -1722,10 +1722,10 @@ public Cffu<T> unsafeOrTimeout(long timeout, TimeUnit unit) {
* @param value the value to use upon timeout
* @param timeout how long to wait before completing normally with the given value, in units of {@code unit}
* @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter
* @see #completeOnTimeout(Object, Executor, long, TimeUnit)
* @see #completeOnTimeout(Object, long, TimeUnit, Executor)
*/
public Cffu<T> completeOnTimeout(@Nullable T value, long timeout, TimeUnit unit) {
return completeOnTimeout(value, fac.defaultExecutor(), timeout, unit);
return completeOnTimeout(value, timeout, unit, fac.defaultExecutor());
}

/**
Expand All @@ -1741,13 +1741,13 @@ public Cffu<T> completeOnTimeout(@Nullable T value, long timeout, TimeUnit unit)
* >DelayDysfunctionDemo</a>.
*
* @param value the value to use upon timeout
* @param executorWhenTimeout the async executor when triggered by timeout
* @param timeout how long to wait before completing normally with the given value, in units of {@code unit}
* @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter
* @param executorWhenTimeout the async executor when triggered by timeout
*/
public Cffu<T> completeOnTimeout(@Nullable T value, Executor executorWhenTimeout, long timeout, TimeUnit unit) {
public Cffu<T> completeOnTimeout(@Nullable T value, long timeout, TimeUnit unit, Executor executorWhenTimeout) {
checkMinimalStage();
return resetCf(CompletableFutureUtils.cffuCompleteOnTimeout(cf, value, executorWhenTimeout, timeout, unit));
return resetCf(CompletableFutureUtils.cffuCompleteOnTimeout(cf, value, timeout, unit, executorWhenTimeout));
}

/**
Expand Down
14 changes: 7 additions & 7 deletions cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public final <T> Cffu<List<T>> mSupplyFailFastAsync(Executor executor, Supplier<
@SafeVarargs
public final <T> Cffu<List<T>> mSupplyAllSuccessAsync(
@Nullable T valueIfFailed, Supplier<? extends T>... suppliers) {
return mSupplyAllSuccessAsync(valueIfFailed, defaultExecutor, suppliers);
return mSupplyAllSuccessAsync(defaultExecutor, valueIfFailed, suppliers);
}

/**
Expand All @@ -206,8 +206,8 @@ public final <T> Cffu<List<T>> mSupplyAllSuccessAsync(
*/
@SafeVarargs
public final <T> Cffu<List<T>> mSupplyAllSuccessAsync(
@Nullable T valueIfFailed, Executor executor, Supplier<? extends T>... suppliers) {
return create(CompletableFutureUtils.mSupplyAllSuccessAsync(valueIfFailed, executor, suppliers));
Executor executor, @Nullable T valueIfFailed, Supplier<? extends T>... suppliers) {
return create(CompletableFutureUtils.mSupplyAllSuccessAsync(executor, valueIfFailed, suppliers));
}

/**
Expand All @@ -220,7 +220,7 @@ public final <T> Cffu<List<T>> mSupplyAllSuccessAsync(
@SafeVarargs
public final <T> Cffu<List<T>> mSupplyMostSuccessAsync(
@Nullable T valueIfNotSuccess, long timeout, TimeUnit unit, Supplier<? extends T>... suppliers) {
return mSupplyMostSuccessAsync(valueIfNotSuccess, defaultExecutor, timeout, unit, suppliers);
return mSupplyMostSuccessAsync(defaultExecutor, valueIfNotSuccess, timeout, unit, suppliers);
}

/**
Expand All @@ -232,9 +232,9 @@ public final <T> Cffu<List<T>> mSupplyMostSuccessAsync(
*/
@SafeVarargs
public final <T> Cffu<List<T>> mSupplyMostSuccessAsync(
@Nullable T valueIfNotSuccess, Executor executor, long timeout, TimeUnit unit,
Executor executor, @Nullable T valueIfNotSuccess, long timeout, TimeUnit unit,
Supplier<? extends T>... suppliers) {
return create(CompletableFutureUtils.mSupplyMostSuccessAsync(valueIfNotSuccess, executor, timeout, unit, suppliers));
return create(CompletableFutureUtils.mSupplyMostSuccessAsync(executor, valueIfNotSuccess, timeout, unit, suppliers));
}

/**
Expand Down Expand Up @@ -793,7 +793,7 @@ public final <T> Cffu<List<T>> allSuccessResultsOf(
public final <T> Cffu<List<T>> mostSuccessResultsOf(
@Nullable T valueIfNotSuccess, long timeout, TimeUnit unit, CompletionStage<? extends T>... cfs) {
return create(CompletableFutureUtils.mostSuccessResultsOf(
valueIfNotSuccess, defaultExecutor, timeout, unit, cfs));
defaultExecutor, valueIfNotSuccess, timeout, unit, cfs));
}

/**
Expand Down
Loading

0 comments on commit fc1761c

Please sign in to comment.