mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-04 06:33:07 +00:00
do not crash polling when just unsubscribed
This commit is contained in:
parent
c6a59b5187
commit
f15d55f513
@ -171,25 +171,23 @@ proc new*(_: type JsonRpcSubscriptions,
|
|||||||
discard
|
discard
|
||||||
|
|
||||||
proc getChanges(id: JsonNode): Future[JsonNode] {.async: (raises: [CancelledError]).} =
|
proc getChanges(id: JsonNode): Future[JsonNode] {.async: (raises: [CancelledError]).} =
|
||||||
try:
|
if mappedId =? subscriptions.subscriptionMapping.?[id]:
|
||||||
let mappedId = subscriptions.subscriptionMapping[id]
|
try:
|
||||||
let changes = await subscriptions.client.eth_getFilterChanges(mappedId)
|
let changes = await subscriptions.client.eth_getFilterChanges(mappedId)
|
||||||
if changes.kind == JArray:
|
if changes.kind == JArray:
|
||||||
return changes
|
return changes
|
||||||
except KeyError as error:
|
except JsonRpcError:
|
||||||
raiseAssert "subscription mapping invalid: " & error.msg
|
await resubscribe(id)
|
||||||
except JsonRpcError:
|
# TODO: we could still miss some events between losing the subscription
|
||||||
await resubscribe(id)
|
# and resubscribing. We should probably adopt a strategy like ethers.js,
|
||||||
# TODO: we could still miss some events between losing the subscription
|
# whereby we keep track of the latest block number that we've seen
|
||||||
# and resubscribing. We should probably adopt a strategy like ethers.js,
|
# filter changes for:
|
||||||
# whereby we keep track of the latest block number that we've seen
|
# https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/base-provider.ts#L977
|
||||||
# filter changes for:
|
except CancelledError as error:
|
||||||
# https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/base-provider.ts#L977
|
raise error
|
||||||
except CancelledError as error:
|
except CatchableError:
|
||||||
raise error
|
# there's nothing we can do here
|
||||||
except CatchableError:
|
discard
|
||||||
# there's nothing we can do here
|
|
||||||
discard
|
|
||||||
return newJArray()
|
return newJArray()
|
||||||
|
|
||||||
proc poll(id: JsonNode) {.async: (raises: [CancelledError]).} =
|
proc poll(id: JsonNode) {.async: (raises: [CancelledError]).} =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user