mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-03 06:03:09 +00:00
untilCancelled template
This commit is contained in:
parent
3a76fa74f1
commit
50cfd9d9dd
6
ethers/providers/jsonrpc/looping.nim
Normal file
6
ethers/providers/jsonrpc/looping.nim
Normal file
@ -0,0 +1,6 @@
|
||||
template untilCancelled*(body) =
|
||||
try:
|
||||
while true:
|
||||
body
|
||||
except CancelledError:
|
||||
raise
|
||||
@ -6,6 +6,7 @@ import ../../basics
|
||||
import ../../provider
|
||||
import ./rpccalls
|
||||
import ./conversions
|
||||
import ./looping
|
||||
|
||||
type
|
||||
JsonRpcSubscriptions* = ref object of RootObj
|
||||
@ -110,13 +111,10 @@ proc new*(_: type JsonRpcSubscriptions,
|
||||
callback(id, change)
|
||||
|
||||
proc poll {.async.} =
|
||||
try:
|
||||
while true:
|
||||
for id in toSeq subscriptions.callbacks.keys:
|
||||
await poll(id)
|
||||
await sleepAsync(pollingInterval)
|
||||
except CancelledError:
|
||||
raise
|
||||
untilCancelled:
|
||||
for id in toSeq subscriptions.callbacks.keys:
|
||||
await poll(id)
|
||||
await sleepAsync(pollingInterval)
|
||||
|
||||
asyncSpawn poll()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user