mirror of
https://github.com/status-im/nim-ethers.git
synced 2025-02-09 22:03:49 +00:00
makes sure that a key on subscriptionMapping exists before trying to access it
This commit is contained in:
parent
d88e4614b1
commit
4642545309
@ -285,15 +285,16 @@ method unsubscribe*(subscriptions: PollingSubscriptions,
|
|||||||
{.async.} =
|
{.async.} =
|
||||||
subscriptions.logFilters.del(id)
|
subscriptions.logFilters.del(id)
|
||||||
subscriptions.callbacks.del(id)
|
subscriptions.callbacks.del(id)
|
||||||
let sub = subscriptions.subscriptionMapping[id]
|
if subscriptions.subscriptionMapping.hasKey(id):
|
||||||
subscriptions.subscriptionMapping.del(id)
|
let sub = subscriptions.subscriptionMapping[id]
|
||||||
try:
|
subscriptions.subscriptionMapping.del(id)
|
||||||
discard await subscriptions.client.eth_uninstallFilter(sub)
|
try:
|
||||||
except CancelledError as e:
|
discard await subscriptions.client.eth_uninstallFilter(sub)
|
||||||
raise e
|
except CancelledError as e:
|
||||||
except CatchableError:
|
raise e
|
||||||
# Ignore if uninstallation of the filter fails. If it's the last step in our
|
except CatchableError:
|
||||||
# cleanup, then filter changes for this filter will no longer be polled so
|
# Ignore if uninstallation of the filter fails. If it's the last step in our
|
||||||
# if the filter continues to live on in geth for whatever reason then it
|
# cleanup, then filter changes for this filter will no longer be polled so
|
||||||
# doesn't matter.
|
# if the filter continues to live on in geth for whatever reason then it
|
||||||
discard
|
# doesn't matter.
|
||||||
|
discard
|
||||||
|
@ -49,6 +49,15 @@ template subscriptionTests(subscriptions, client) =
|
|||||||
discard await client.call("evm_mine", newJArray())
|
discard await client.call("evm_mine", newJArray())
|
||||||
await sleepAsync(100.millis)
|
await sleepAsync(100.millis)
|
||||||
check count == 0
|
check count == 0
|
||||||
|
|
||||||
|
test "unsubscribing from a non-existent subscription does not do any harm":
|
||||||
|
await subscriptions.unsubscribe(newJInt(0))
|
||||||
|
|
||||||
|
test "duplicate unsubscribe is harmless":
|
||||||
|
proc callback(blck: Block) = discard
|
||||||
|
let subscription = await subscriptions.subscribeBlocks(callback)
|
||||||
|
await subscriptions.unsubscribe(subscription)
|
||||||
|
await subscriptions.unsubscribe(subscription)
|
||||||
|
|
||||||
test "stops listening to new blocks when provider is closed":
|
test "stops listening to new blocks when provider is closed":
|
||||||
var count = 0
|
var count = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user