From 359f04e7ec717509447968ec73fa285f75ab0a95 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Thu, 20 Mar 2025 16:16:52 +0100 Subject: [PATCH] Rename the symbol for better clarity --- Readme.md | 2 +- config.nims | 1 + ethers/providers/jsonrpc/subscriptions.nim | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 8689694..807047a 100644 --- a/Readme.md +++ b/Readme.md @@ -209,7 +209,7 @@ Workaround If you're working with Hardhat, you might encounter an issue where [subscriptions stop working after 5 minutes](https://github.com/NomicFoundation/hardhat/issues/2053). -This library provides a workaround using the `--define:resubscribe` option. When this symbol is defined, the subscriptions will automatically resubscribe after 4 minutes. +This library provides a workaround using the `--define:ws_resubscribe` option. When this symbol is defined, the subscriptions will automatically resubscribe after 4 minutes. Contribution ------------ diff --git a/config.nims b/config.nims index 6181efc..2d9d42f 100644 --- a/config.nims +++ b/config.nims @@ -8,3 +8,4 @@ when fileExists("nimble.paths"): when (NimMajor, NimMinor) >= (2, 0): --mm:refc + --define:ws_resubscribe diff --git a/ethers/providers/jsonrpc/subscriptions.nim b/ethers/providers/jsonrpc/subscriptions.nim index 8ac7060..4413f54 100644 --- a/ethers/providers/jsonrpc/subscriptions.nim +++ b/ethers/providers/jsonrpc/subscriptions.nim @@ -24,14 +24,14 @@ type # about them # This is used of resubscribe all the subscriptions when using websocket with hardhat logFilters: Table[JsonNode, EventFilter] - when defined(resubscribe): + when defined(ws_resubscribe): resubscribeFut: Future[void] MethodHandler* = proc (j: JsonNode) {.gcsafe, raises: [].} SubscriptionCallback = proc(id: JsonNode, arguments: ?!JsonNode) {.gcsafe, raises:[].} {.push raises:[].} -when defined(resubscribe): +when defined(ws_resubscribe): # This is a workaround to manage the 5 minutes limit due to hardhat. # See https://github.com/NomicFoundation/hardhat/issues/2053#issuecomment-1061374064 proc resubscribeWebsocketEventsOnTimeout*(subscriptions: JsonRpcSubscriptions) {.async.} = @@ -110,7 +110,7 @@ method close*(subscriptions: JsonRpcSubscriptions) {.async: (raises: [Subscripti for id in ids: await subscriptions.unsubscribe(id) - when defined(resubscribe): + when defined(ws_resubscribe): if not subscriptions.resubscribeFut.isNil: await subscriptions.resubscribeFut.cancelAndWait() @@ -136,7 +136,7 @@ proc new*(_: type JsonRpcSubscriptions, callback(id, success(arguments)) subscriptions.setMethodHandler("eth_subscription", subscriptionHandler) - when defined(resubscribe): + when defined(ws_resubscribe): subscriptions.resubscribeFut = resubscribeWebsocketEventsOnTimeout(subscriptions) subscriptions