`untilCancelled` template

This commit is contained in:
Mark Spanbroek 2023-06-27 14:44:03 +02:00 committed by markspanbroek
parent 3a76fa74f1
commit 50cfd9d9dd
2 changed files with 11 additions and 7 deletions

View File

@ -0,0 +1,6 @@
template untilCancelled*(body) =
try:
while true:
body
except CancelledError:
raise

View File

@ -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()