Skip to content

Commit

Permalink
perf: optimize ItemHolder#getOpFuture
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Oct 4, 2024
1 parent 4febfeb commit 55e2a7f
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ItemHolder<K, V, Ctx, UserData> {

public static final IllegalStateException UNLOADED_EXCEPTION = new IllegalStateException("Not loaded");
private static final CompletableFuture<Void> UNLOADED_FUTURE = CompletableFuture.failedFuture(UNLOADED_EXCEPTION);
private static final CompletableFuture<Void> COMPLETED_VOID_FUTURE = CompletableFuture.completedFuture(null);

@SuppressWarnings("PointlessBitwiseExpression")
public static final int FLAG_REMOVED = 1 << 0;
Expand Down Expand Up @@ -169,8 +170,11 @@ public void tryCancelUpgradeAction() {
}
}

public CompletableFuture<Void> getOpFuture() {
public CompletableFuture<Void> getOpFuture() { // best-effort
assertOpen();
if (!this.busyRefCounter.isBusy()) {
return COMPLETED_VOID_FUTURE;
}
CompletableFuture<Void> future = new CompletableFuture<>();
this.busyRefCounter.addListener(() -> future.complete(null));
return future;
Expand Down

0 comments on commit 55e2a7f

Please sign in to comment.