fixes #24506; calculate timeout correctly (#24507)

`curTimeout` is calculated incorrectly. So this PR fixes it.
This PR also replaces `now()` with `getMonoTime()`.
This commit is contained in:
Tomohiro
2024-12-04 23:11:32 +09:00
committed by GitHub
parent 6bbf9c3117
commit bbf6a62c90

View File

@@ -1696,12 +1696,12 @@ proc drain*(timeout = 500) =
## Waits for completion of **all** events and processes them. Raises `ValueError`
## if there are no pending operations. In contrast to `poll` this
## processes as many events as are available until the timeout has elapsed.
var curTimeout = timeout
let start = now()
var elapsed = 0
let start = getMonoTime()
while hasPendingOperations():
discard runOnce(curTimeout)
curTimeout -= (now() - start).inMilliseconds.int
if curTimeout < 0:
discard runOnce(timeout - elapsed)
elapsed = (getMonoTime() - start).inMilliseconds
if elapsed >= timeout:
break
proc poll*(timeout = 500) =