Skip to content

Commit

Permalink
feat: add resetDefaultExecutor method to CffuFactory/Cffu🏭
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Jul 27, 2024
1 parent 127c439 commit f94a27c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 9 additions & 4 deletions cffu-core/src/main/java/io/foldright/cffu/Cffu.java
Original file line number Diff line number Diff line change
Expand Up @@ -2722,10 +2722,15 @@ public CompletionStage<T> minimalCompletionStage() {
}

/**
* Returns a new Cffu with the given CffuFactory(contained configuration)
* that is completed normally with the same value as this Cffu when it completes normally.
* If this Cffu completes exceptionally, then the returned Cffu completes exceptionally
* with a CompletionException with this exception as cause.
* Returns a new Cffu with the given defaultExecutor.
*/
@Contract(pure = true)
public Cffu<T> resetDefaultExecutor(Executor defaultExecutor) {
return new Cffu<>(fac.resetDefaultExecutor(defaultExecutor), isMinimalStage, cf);
}

/**
* Returns a new Cffu with the given CffuFactory(contained configuration).
* <p>
* demo code about re-config methods of Cffu:
*
Expand Down
14 changes: 11 additions & 3 deletions cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public static CffuFactoryBuilder builder(Executor defaultExecutor) {
return new CffuFactoryBuilder(CompletableFutureUtils.screenExecutor(defaultExecutor));
}

/**
* Returns a new CffuFactory from this CffuFactory that reset the defaultExecutor.
*/
@Contract(pure = true)
CffuFactory resetDefaultExecutor(Executor defaultExecutor) {
return new CffuFactory(defaultExecutor, forbidObtrudeMethods);
}

@Contract(pure = true)
private <T> Cffu<T> create(CompletableFuture<T> cf) {
return new Cffu<>(this, false, cf);
Expand Down Expand Up @@ -1050,9 +1058,9 @@ public final <T> Cffu<List<T>> allSuccessResultsOf(
* If the given stage is successful, its result is the completed value; Otherwise the given valueIfNotSuccess.
*
* @param valueIfNotSuccess the value to return if not completed successfully
* @param timeout how long to wait in units of {@code unit}
* @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter
* @param cfs the stages
* @param timeout how long to wait in units of {@code unit}
* @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter
* @param cfs the stages
* @see Cffu#getSuccessNow(Object)
*/
@Contract(pure = true)
Expand Down

0 comments on commit f94a27c

Please sign in to comment.