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.} =
|
||||
raiseAssert "not implemented"
|
||||
|
||||
method close*(subscriptions: JsonRpcSubscriptions) {.async.} =
|
||||
method close*(subscriptions: JsonRpcSubscriptions) {.async, base.} =
|
||||
let ids = toSeq subscriptions.callbacks.keys
|
||||
for id in ids:
|
||||
await subscriptions.unsubscribe(id)
|
||||
|
@ -103,6 +103,7 @@ method unsubscribe(subscriptions: WebSocketSubscriptions,
|
|||
|
||||
type
|
||||
PollingSubscriptions = ref object of JsonRpcSubscriptions
|
||||
polling: Future[void]
|
||||
|
||||
proc new*(_: type JsonRpcSubscriptions,
|
||||
client: RpcHttpClient,
|
||||
|
@ -127,10 +128,13 @@ proc new*(_: type JsonRpcSubscriptions,
|
|||
await poll(id)
|
||||
await sleepAsync(pollingInterval)
|
||||
|
||||
asyncSpawn poll()
|
||||
|
||||
subscriptions.polling = poll()
|
||||
subscriptions
|
||||
|
||||
method close*(subscriptions: PollingSubscriptions) {.async.} =
|
||||
await subscriptions.polling.cancelAndWait()
|
||||
await procCall JsonRpcSubscriptions(subscriptions).close()
|
||||
|
||||
method subscribeBlocks(subscriptions: PollingSubscriptions,
|
||||
onBlock: BlockHandler):
|
||||
Future[JsonRpcSubscription]
|
||||
|
|
Loading…
Reference in New Issue