Skip to content

Commit

Permalink
Add an andThen to the Websocket on close
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Jan 21, 2025
1 parent 889e740 commit a8012ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.net.http.HttpClient;
import java.net.http.WebSocket;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
Expand All @@ -26,6 +27,15 @@ interface OnClose {
void accept(final SolanaRpcWebsocket websocket,
final int statusCode,
final String reason);

default OnClose andThen(final OnClose after) {
Objects.requireNonNull(after);

return (ws, c, r) -> {
accept(ws, c, r);
after.accept(ws, c, r);
};
}
}

static Builder build() {
Expand Down Expand Up @@ -190,7 +200,7 @@ default Builder writeOrPingDelay(final long writeOrPingDelay) {

Builder onOpen(final Consumer<SolanaRpcWebsocket> onOpen);

OnClose onclose();
OnClose onClose();

/// The default behavior is to [#close()] this WebSocket.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public SolanaRpcWebsocket.Builder onOpen(final Consumer<SolanaRpcWebsocket> onOp
}

@Override
public SolanaRpcWebsocket.OnClose onclose() {
public SolanaRpcWebsocket.OnClose onClose() {
return onClose;
}

Expand Down

0 comments on commit a8012ad

Please sign in to comment.