From a8012adb47585173a4710b0cc4d974005cc50447 Mon Sep 17 00:00:00 2001 From: jpe7s Date: Mon, 20 Jan 2025 18:58:57 -0600 Subject: [PATCH] Add an andThen to the Websocket on close --- .../sava/rpc/json/http/ws/SolanaRpcWebsocket.java | 12 +++++++++++- .../rpc/json/http/ws/SolanaRpcWebsocketBuilder.java | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/rpc/src/main/java/software/sava/rpc/json/http/ws/SolanaRpcWebsocket.java b/rpc/src/main/java/software/sava/rpc/json/http/ws/SolanaRpcWebsocket.java index 770aec7..c466f4d 100644 --- a/rpc/src/main/java/software/sava/rpc/json/http/ws/SolanaRpcWebsocket.java +++ b/rpc/src/main/java/software/sava/rpc/json/http/ws/SolanaRpcWebsocket.java @@ -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; @@ -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() { @@ -190,7 +200,7 @@ default Builder writeOrPingDelay(final long writeOrPingDelay) { Builder onOpen(final Consumer onOpen); - OnClose onclose(); + OnClose onClose(); /// The default behavior is to [#close()] this WebSocket. /// diff --git a/rpc/src/main/java/software/sava/rpc/json/http/ws/SolanaRpcWebsocketBuilder.java b/rpc/src/main/java/software/sava/rpc/json/http/ws/SolanaRpcWebsocketBuilder.java index a737692..0c9a334 100644 --- a/rpc/src/main/java/software/sava/rpc/json/http/ws/SolanaRpcWebsocketBuilder.java +++ b/rpc/src/main/java/software/sava/rpc/json/http/ws/SolanaRpcWebsocketBuilder.java @@ -126,7 +126,7 @@ public SolanaRpcWebsocket.Builder onOpen(final Consumer onOp } @Override - public SolanaRpcWebsocket.OnClose onclose() { + public SolanaRpcWebsocket.OnClose onClose() { return onClose; }