* Fix asyncdispatch drain behavior (#14820) * Changed test to use asyncCheck instead of discard after code review (#14820) * Added some debug statements to help understand what is happening in Azure. * Removed debug statements and increased timeouts by 1 order of magnitude to account for slow Azure VMs Co-authored-by: Ray Imber <ray@crankuptheamps.com>
This commit is contained in:
parent
8be54b8fa7
commit
36fa79a524
2 changed files with 34 additions and 4 deletions
|
|
@ -1601,11 +1601,16 @@ else:
|
||||||
p.selector.registerEvent(SelectEvent(ev), data)
|
p.selector.registerEvent(SelectEvent(ev), data)
|
||||||
|
|
||||||
proc drain*(timeout = 500) =
|
proc drain*(timeout = 500) =
|
||||||
## Waits for completion events and processes them. Raises ``ValueError``
|
## Waits for completion of **all** events and processes them. Raises ``ValueError``
|
||||||
## if there are no pending operations. In contrast to ``poll`` this
|
## if there are no pending operations. In contrast to ``poll`` this
|
||||||
## processes as many events as are available.
|
## processes as many events as are available until the timeout has elapsed.
|
||||||
if runOnce(timeout) or hasPendingOperations():
|
var curTimeout = timeout
|
||||||
while hasPendingOperations() and runOnce(timeout): discard
|
let start = now()
|
||||||
|
while hasPendingOperations():
|
||||||
|
discard runOnce(curTimeout)
|
||||||
|
curTimeout -= (now() - start).inMilliseconds.int
|
||||||
|
if curTimeout < 0:
|
||||||
|
break
|
||||||
|
|
||||||
proc poll*(timeout = 500) =
|
proc poll*(timeout = 500) =
|
||||||
## Waits for completion events and processes them. Raises ``ValueError``
|
## Waits for completion events and processes them. Raises ``ValueError``
|
||||||
|
|
|
||||||
25
tests/async/t14820.nim
Normal file
25
tests/async/t14820.nim
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
iteration: 1
|
||||||
|
iteration: 2
|
||||||
|
iteration: 3
|
||||||
|
iteration: 4
|
||||||
|
async done
|
||||||
|
iteration: 5
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import asyncdispatch, times
|
||||||
|
|
||||||
|
var done = false
|
||||||
|
proc somethingAsync() {.async.} =
|
||||||
|
yield sleepAsync 5000
|
||||||
|
echo "async done"
|
||||||
|
done = true
|
||||||
|
|
||||||
|
asyncCheck somethingAsync()
|
||||||
|
var count = 0
|
||||||
|
while not done:
|
||||||
|
count += 1
|
||||||
|
drain 1000
|
||||||
|
echo "iteration: ", count
|
||||||
Loading…
Add table
Add a link
Reference in a new issue