Skip to content

Commit

Permalink
perf: simplify hopExecutorIfAtCfDelayerThread, submit completion ac…
Browse files Browse the repository at this point in the history
…tion to executor directly 🧵
  • Loading branch information
oldratlee committed Aug 22, 2024
1 parent 1e344cc commit 30b912f
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3833,13 +3833,12 @@ C completeOnTimeout(C cfThis, @Nullable T value, long timeout, TimeUnit unit) {
}

@SuppressWarnings("unchecked")
private static <C extends CompletableFuture<?>> C hopExecutorIfAtCfDelayerThread(C cf, Executor asyncExecutor) {
private static <C extends CompletableFuture<?>> C hopExecutorIfAtCfDelayerThread(C cf, Executor executor) {
CompletableFuture<Object> ret = newIncompleteFuture(cf);

cf.handle((v, ex) -> {
if (!atCfDelayerThread()) completeCf(ret, v, ex);
else delayedExecutor(0, TimeUnit.SECONDS, asyncExecutor)
.execute(() -> completeCf(ret, v, ex));
else executor.execute(() -> completeCf(ret, v, ex));
// use `cf.handle` method(instead of `cf.whenComplete`) and return null
// in order to prevent reporting the handled argument exception in this `action` in subsequent `exceptionally`
return null;
Expand Down

0 comments on commit 30b912f

Please sign in to comment.