Skip to content

Commit

Permalink
perf: use cffuCompleteOnTimeout instead of cffuOrTimeout in `most…
Browse files Browse the repository at this point in the history
…Of*` methods for multiply input cfs ⚡️

`cffuCompleteOnTimeout` won't create `TimeoutException`
  • Loading branch information
oldratlee committed Jun 6, 2024
1 parent 2c00e27 commit ed817b9
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public static <T> CompletableFuture<List<T>> mostResultsOfSuccess(
// MUST be non-minimal-stage CF instances in order to read results(`getSuccessNow`),
// otherwise UnsupportedOperationException
final CompletableFuture<T>[] cfArray = f_toNonMinCfArray(cfs);
return cffuOrTimeout(CompletableFuture.allOf(cfArray), executorWhenTimeout, timeout, unit)
return cffuCompleteOnTimeout(CompletableFuture.allOf(cfArray), null, executorWhenTimeout, timeout, unit)
.handle((unused, ex) -> arrayList(MGetSuccessNow0(valueIfNotSuccess, cfArray)));
}

Expand Down Expand Up @@ -800,7 +800,7 @@ private static <T> CompletableFuture<T> mostTupleOfSuccess0(
// MUST be *Non-Minimal* CF instances in order to read results(`getSuccessNow`),
// otherwise UnsupportedOperationException
final CompletableFuture<Object>[] cfArray = f_toNonMinCfArray(css);
return cffuOrTimeout(CompletableFuture.allOf(cfArray), executorWhenTimeout, timeout, unit)
return cffuCompleteOnTimeout(CompletableFuture.allOf(cfArray), null, executorWhenTimeout, timeout, unit)
.handle((unused, ex) -> tupleOf0(MGetSuccessNow0(null, cfArray)));
}

Expand Down Expand Up @@ -1513,8 +1513,7 @@ public static <C extends CompletableFuture<?>> C cffuOrTimeout(
requireNonNull(executorWhenTimeout, "executorWhenTimeout is null");
requireNonNull(unit, "unit is null");

final C f = orTimeout(cf, timeout, unit);
return hopExecutorIfAtCfDelayerThread(f, executorWhenTimeout);
return hopExecutorIfAtCfDelayerThread(orTimeout(cf, timeout, unit), executorWhenTimeout);
}

/**
Expand Down Expand Up @@ -1589,8 +1588,7 @@ C cffuCompleteOnTimeout(C cf, @Nullable T value, Executor executorWhenTimeout, l
requireNonNull(executorWhenTimeout, "executorWhenTimeout is null");
requireNonNull(unit, "unit is null");

final C f = completeOnTimeout(cf, value, timeout, unit);
return hopExecutorIfAtCfDelayerThread(f, executorWhenTimeout);
return hopExecutorIfAtCfDelayerThread(completeOnTimeout(cf, value, timeout, unit), executorWhenTimeout);
}

/**
Expand Down

0 comments on commit ed817b9

Please sign in to comment.