Make polling interval configurable
This commit is contained in:
parent
beac903a3f
commit
3a76fa74f1
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue