`untilCancelled` template
This commit is contained in:
parent
3a76fa74f1
commit
50cfd9d9dd
|
@ -0,0 +1,6 @@
|
||||||
|
template untilCancelled*(body) =
|
||||||
|
try:
|
||||||
|
while true:
|
||||||
|
body
|
||||||
|
except CancelledError:
|
||||||
|
raise
|
|
@ -6,6 +6,7 @@ import ../../basics
|
||||||
import ../../provider
|
import ../../provider
|
||||||
import ./rpccalls
|
import ./rpccalls
|
||||||
import ./conversions
|
import ./conversions
|
||||||
|
import ./looping
|
||||||
|
|
||||||
type
|
type
|
||||||
JsonRpcSubscriptions* = ref object of RootObj
|
JsonRpcSubscriptions* = ref object of RootObj
|
||||||
|
@ -110,13 +111,10 @@ proc new*(_: type JsonRpcSubscriptions,
|
||||||
callback(id, change)
|
callback(id, change)
|
||||||
|
|
||||||
proc poll {.async.} =
|
proc poll {.async.} =
|
||||||
try:
|
untilCancelled:
|
||||||
while true:
|
|
||||||
for id in toSeq subscriptions.callbacks.keys:
|
for id in toSeq subscriptions.callbacks.keys:
|
||||||
await poll(id)
|
await poll(id)
|
||||||
await sleepAsync(pollingInterval)
|
await sleepAsync(pollingInterval)
|
||||||
except CancelledError:
|
|
||||||
raise
|
|
||||||
|
|
||||||
asyncSpawn poll()
|
asyncSpawn poll()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue