From e86f63672541bb26059e5cd272ccc03f01ac3f87 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Wed, 26 Mar 2025 14:55:42 +0100 Subject: [PATCH] Update wording --- ethers/providers/jsonrpc/subscriptions.nim | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ethers/providers/jsonrpc/subscriptions.nim b/ethers/providers/jsonrpc/subscriptions.nim index 4413f54..7ae2f95 100644 --- a/ethers/providers/jsonrpc/subscriptions.nim +++ b/ethers/providers/jsonrpc/subscriptions.nim @@ -19,10 +19,11 @@ type client: RpcClient callbacks: Table[JsonNode, SubscriptionCallback] methodHandlers: Table[string, MethodHandler] - # We need to keep around the filters that are used to create log filters on the RPC node - # as there might be a time when they need to be recreated as RPC node might prune/forget - # about them - # This is used of resubscribe all the subscriptions when using websocket with hardhat + # Used by both PollingSubscriptions and WebsocketSubscriptions to store + # subscription filters so the subscriptions can be recreated. With + # PollingSubscriptions, the RPC node might prune/forget about them, and with + # WebsocketSubscriptions, when using hardhat, subscriptions are dropped after 5 + # minutes. logFilters: Table[JsonNode, EventFilter] when defined(ws_resubscribe): resubscribeFut: Future[void] @@ -110,10 +111,6 @@ method close*(subscriptions: JsonRpcSubscriptions) {.async: (raises: [Subscripti for id in ids: await subscriptions.unsubscribe(id) - when defined(ws_resubscribe): - if not subscriptions.resubscribeFut.isNil: - await subscriptions.resubscribeFut.cancelAndWait() - proc getCallback(subscriptions: JsonRpcSubscriptions, id: JsonNode): ?SubscriptionCallback {. raises:[].} = try: @@ -189,6 +186,11 @@ method unsubscribe*(subscriptions: WebSocketSubscriptions, # Ignore if uninstallation of the subscribiton fails. discard +method close*(subscriptions: WebsocketSubscriptions) {.async.} = + await procCall JsonRpcSubscriptions(subscriptions).close() + if not subscriptions.resubscribeFut.isNil: + await subscriptions.resubscribeFut.cancelAndWait() + # Polling type