From fd5d158fbd0c5527ac918059d34312a209877dee Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:46:59 +1100 Subject: [PATCH] fix(timer): ensure timer loop is asyncSpawned --- codex/utils/timer.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codex/utils/timer.nim b/codex/utils/timer.nim index 9361d07b4..0235abfc5 100644 --- a/codex/utils/timer.nim +++ b/codex/utils/timer.nim @@ -30,13 +30,13 @@ proc new*(T: type Timer, timerName = "Unnamed Timer"): Timer = ## Create a new Timer intance with the given name Timer(name: timerName) -proc timerLoop(timer: Timer) {.async.} = +proc timerLoop(timer: Timer) {.async: (raises: []).} = try: while true: await timer.callback() await sleepAsync(timer.interval) except CancelledError: - raise + discard # do not propagate as timerLoop is asyncSpawned except CatchableError as exc: error "Timer caught unhandled exception: ", name=timer.name, msg=exc.msg @@ -47,6 +47,7 @@ method start*(timer: Timer, callback: TimerCallback, interval: Duration) {.base. timer.callback = callback timer.interval = interval timer.loopFuture = timerLoop(timer) + asyncSpawn timer.loopFuture method stop*(timer: Timer) {.async, base.} = if timer.loopFuture != nil: