Make polling interval configurable

This commit is contained in:
Mark Spanbroek 2023-06-27 14:33:14 +02:00 committed by markspanbroek
parent beac903a3f
commit 3a76fa74f1
2 changed files with 5 additions and 3 deletions

View File

@ -99,7 +99,8 @@ type
PollingSubscriptions = ref object of JsonRpcSubscriptions PollingSubscriptions = ref object of JsonRpcSubscriptions
proc new*(_: type JsonRpcSubscriptions, proc new*(_: type JsonRpcSubscriptions,
client: RpcHttpClient): JsonRpcSubscriptions = client: RpcHttpClient,
pollingInterval = 4.seconds): JsonRpcSubscriptions =
let subscriptions = PollingSubscriptions(client: client) let subscriptions = PollingSubscriptions(client: client)
@ -113,7 +114,7 @@ proc new*(_: type JsonRpcSubscriptions,
while true: while true:
for id in toSeq subscriptions.callbacks.keys: for id in toSeq subscriptions.callbacks.keys:
await poll(id) await poll(id)
await sleepAsync(1.seconds) await sleepAsync(pollingInterval)
except CancelledError: except CancelledError:
raise raise

View File

@ -49,6 +49,7 @@ suite "HTTP polling subscriptions":
setup: setup:
client = newRpcHttpClient() client = newRpcHttpClient()
await client.connect("http://localhost:8545") await client.connect("http://localhost:8545")
subscriptions = JsonRpcSubscriptions.new(client) subscriptions = JsonRpcSubscriptions.new(client,
pollingInterval = 100.millis)
subscriptionTests(subscriptions, client) subscriptionTests(subscriptions, client)