Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions chronos/internal/asyncengine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ template processTimersGetTimeout(loop, timeout: untyped) =
timeout = (lastFinish - curTime).getAsyncTimestamp()

if timeout == 0:
if (len(loop.callbacks) == 0) and (len(loop.idlers) == 0):
if (len(loop.callbacks) == 0) and (len(loop.idlers) == 0) and
(len(loop.ticks) == 0):
when defined(windows):
timeout = INFINITE
else:
timeout = -1
else:
if (len(loop.callbacks) != 0) or (len(loop.idlers) != 0):
if (len(loop.callbacks) != 0) or (len(loop.idlers) != 0) or
(len(loop.ticks) != 0):
timeout = 0

template processTimers(loop: untyped) =
Expand Down
32 changes: 32 additions & 0 deletions tests/testtime.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import std/os
import unittest2
import ../chronos, ../chronos/timer
import ../chronos/timer

{.used.}

Expand Down Expand Up @@ -127,3 +128,34 @@ suite "Asynchronous timers & steps test suite":

check:
fut3.completed() == true

test "Cancellation retry tick does not wait for next timer":
const NextTimerSleep = 50.milliseconds
Comment thread
dryajov marked this conversation as resolved.
Outdated

let gate = newFuture[void]("cancelAndWait.gate")
var
slept = false
workerFut: Future[void]

proc cancelWorker(): Future[void] {.async.} =
await gate
await workerFut.cancelAndWait()

proc worker() {.async.} =
try:
await gate
await sleepAsync(NextTimerSleep)
slept = true
except CancelledError:
discard

let cancelFut = cancelWorker()
workerFut = worker()
gate.complete()

while not cancelFut.finished:
poll()

check:
workerFut.finished
not slept
Loading