Skip to content

Commit

Permalink
don't block request futures in client event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jan 30, 2025
1 parent bceaa84 commit 272345f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/zenith/util/RequestFuture.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.zenith.util;

import com.zenith.Proxy;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -47,14 +48,27 @@ public boolean isDone() {
@SneakyThrows
@Override
public Boolean get() {
var client = Proxy.getInstance().getClient();
if (client != null && client.getClientEventLoop().inEventLoop()) {
throw new IllegalStateException("Cannot block on RequestFuture in client event loop");
}
Wait.waitUntil(() -> completed, 1, 1L, TimeUnit.SECONDS);
return accepted;
}

@SneakyThrows
@Override
public Boolean get(final long timeout, @NotNull final TimeUnit unit) {
var client = Proxy.getInstance().getClient();
if (client != null && client.getClientEventLoop().inEventLoop()) {
throw new IllegalStateException("Cannot block on RequestFuture in client event loop");
}
Wait.waitUntil(() -> completed, 1, timeout, unit);
return accepted;
}

public boolean getNow() {
if (!completed) return false;
return accepted;
}
}

0 comments on commit 272345f

Please sign in to comment.