Stop polling when provider is closed
This commit is contained in:
parent
a27c2de41c
commit
738c6a87e2
|
@ -35,7 +35,7 @@ method unsubscribe(subscriptions: JsonRpcSubscriptions,
|
||||||
{.async, base.} =
|
{.async, base.} =
|
||||||
raiseAssert "not implemented"
|
raiseAssert "not implemented"
|
||||||
|
|
||||||
method close*(subscriptions: JsonRpcSubscriptions) {.async.} =
|
method close*(subscriptions: JsonRpcSubscriptions) {.async, base.} =
|
||||||
let ids = toSeq subscriptions.callbacks.keys
|
let ids = toSeq subscriptions.callbacks.keys
|
||||||
for id in ids:
|
for id in ids:
|
||||||
await subscriptions.unsubscribe(id)
|
await subscriptions.unsubscribe(id)
|
||||||
|
@ -103,6 +103,7 @@ method unsubscribe(subscriptions: WebSocketSubscriptions,
|
||||||
|
|
||||||
type
|
type
|
||||||
PollingSubscriptions = ref object of JsonRpcSubscriptions
|
PollingSubscriptions = ref object of JsonRpcSubscriptions
|
||||||
|
polling: Future[void]
|
||||||
|
|
||||||
proc new*(_: type JsonRpcSubscriptions,
|
proc new*(_: type JsonRpcSubscriptions,
|
||||||
client: RpcHttpClient,
|
client: RpcHttpClient,
|
||||||
|
@ -127,10 +128,13 @@ proc new*(_: type JsonRpcSubscriptions,
|
||||||
await poll(id)
|
await poll(id)
|
||||||
await sleepAsync(pollingInterval)
|
await sleepAsync(pollingInterval)
|
||||||
|
|
||||||
asyncSpawn poll()
|
subscriptions.polling = poll()
|
||||||
|
|
||||||
subscriptions
|
subscriptions
|
||||||
|
|
||||||
|
method close*(subscriptions: PollingSubscriptions) {.async.} =
|
||||||
|
await subscriptions.polling.cancelAndWait()
|
||||||
|
await procCall JsonRpcSubscriptions(subscriptions).close()
|
||||||
|
|
||||||
method subscribeBlocks(subscriptions: PollingSubscriptions,
|
method subscribeBlocks(subscriptions: PollingSubscriptions,
|
||||||
onBlock: BlockHandler):
|
onBlock: BlockHandler):
|
||||||
Future[JsonRpcSubscription]
|
Future[JsonRpcSubscription]
|
||||||
|
|
Loading…
Reference in New Issue