Rename the symbol for better clarity

This commit is contained in:
Arnaud 2025-03-20 16:16:52 +01:00
parent d1b54beec5
commit 359f04e7ec
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
3 changed files with 6 additions and 5 deletions

View File

@ -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). 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 Contribution
------------ ------------

View File

@ -8,3 +8,4 @@ when fileExists("nimble.paths"):
when (NimMajor, NimMinor) >= (2, 0): when (NimMajor, NimMinor) >= (2, 0):
--mm:refc --mm:refc
--define:ws_resubscribe

View File

@ -24,14 +24,14 @@ type
# about them # about them
# This is used of resubscribe all the subscriptions when using websocket with hardhat # This is used of resubscribe all the subscriptions when using websocket with hardhat
logFilters: Table[JsonNode, EventFilter] logFilters: Table[JsonNode, EventFilter]
when defined(resubscribe): when defined(ws_resubscribe):
resubscribeFut: Future[void] resubscribeFut: Future[void]
MethodHandler* = proc (j: JsonNode) {.gcsafe, raises: [].} MethodHandler* = proc (j: JsonNode) {.gcsafe, raises: [].}
SubscriptionCallback = proc(id: JsonNode, arguments: ?!JsonNode) {.gcsafe, raises:[].} SubscriptionCallback = proc(id: JsonNode, arguments: ?!JsonNode) {.gcsafe, raises:[].}
{.push raises:[].} {.push raises:[].}
when defined(resubscribe): when defined(ws_resubscribe):
# This is a workaround to manage the 5 minutes limit due to hardhat. # This is a workaround to manage the 5 minutes limit due to hardhat.
# See https://github.com/NomicFoundation/hardhat/issues/2053#issuecomment-1061374064 # See https://github.com/NomicFoundation/hardhat/issues/2053#issuecomment-1061374064
proc resubscribeWebsocketEventsOnTimeout*(subscriptions: JsonRpcSubscriptions) {.async.} = proc resubscribeWebsocketEventsOnTimeout*(subscriptions: JsonRpcSubscriptions) {.async.} =
@ -110,7 +110,7 @@ method close*(subscriptions: JsonRpcSubscriptions) {.async: (raises: [Subscripti
for id in ids: for id in ids:
await subscriptions.unsubscribe(id) await subscriptions.unsubscribe(id)
when defined(resubscribe): when defined(ws_resubscribe):
if not subscriptions.resubscribeFut.isNil: if not subscriptions.resubscribeFut.isNil:
await subscriptions.resubscribeFut.cancelAndWait() await subscriptions.resubscribeFut.cancelAndWait()
@ -136,7 +136,7 @@ proc new*(_: type JsonRpcSubscriptions,
callback(id, success(arguments)) callback(id, success(arguments))
subscriptions.setMethodHandler("eth_subscription", subscriptionHandler) subscriptions.setMethodHandler("eth_subscription", subscriptionHandler)
when defined(resubscribe): when defined(ws_resubscribe):
subscriptions.resubscribeFut = resubscribeWebsocketEventsOnTimeout(subscriptions) subscriptions.resubscribeFut = resubscribeWebsocketEventsOnTimeout(subscriptions)
subscriptions subscriptions