`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 ./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…
Reference in New Issue