Fixes #4262.
This commit is contained in:
parent
04c1caf025
commit
5bf16439e1
3 changed files with 94 additions and 68 deletions
|
|
@ -500,6 +500,7 @@ when defined(windows) or defined(nimdoc):
|
||||||
raise newException(ValueError,
|
raise newException(ValueError,
|
||||||
"No handles or timers registered in dispatcher.")
|
"No handles or timers registered in dispatcher.")
|
||||||
|
|
||||||
|
if p.handles.len != 0:
|
||||||
let at = p.adjustedTimeout(timeout)
|
let at = p.adjustedTimeout(timeout)
|
||||||
var llTimeout =
|
var llTimeout =
|
||||||
if at == -1: winlean.INFINITE
|
if at == -1: winlean.INFINITE
|
||||||
|
|
@ -1283,6 +1284,8 @@ else:
|
||||||
|
|
||||||
proc poll*(timeout = 500) =
|
proc poll*(timeout = 500) =
|
||||||
let p = getGlobalDispatcher()
|
let p = getGlobalDispatcher()
|
||||||
|
|
||||||
|
if p.selector.len > 0:
|
||||||
for info in p.selector.select(p.adjustedTimeout(timeout)):
|
for info in p.selector.select(p.adjustedTimeout(timeout)):
|
||||||
let data = PData(info.key.data)
|
let data = PData(info.key.data)
|
||||||
assert data.fd == info.key.fd.AsyncFD
|
assert data.fd == info.key.fd.AsyncFD
|
||||||
|
|
|
||||||
|
|
@ -375,6 +375,10 @@ proc contains*(s: Selector, key: SelectorKey): bool =
|
||||||
when not defined(nimdoc):
|
when not defined(nimdoc):
|
||||||
return key.fd in s and s.fds[key.fd] == key
|
return key.fd in s and s.fds[key.fd] == key
|
||||||
|
|
||||||
|
proc len*(s: Selector): int =
|
||||||
|
## Retrieves the number of registered file descriptors in this Selector.
|
||||||
|
return s.fds.len
|
||||||
|
|
||||||
{.deprecated: [TEvent: Event, PSelectorKey: SelectorKey,
|
{.deprecated: [TEvent: Event, PSelectorKey: SelectorKey,
|
||||||
TReadyInfo: ReadyInfo, PSelector: Selector].}
|
TReadyInfo: ReadyInfo, PSelector: Selector].}
|
||||||
|
|
||||||
|
|
|
||||||
19
tests/async/tpolltimeouts.nim
Normal file
19
tests/async/tpolltimeouts.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
discard """
|
||||||
|
output: "true"
|
||||||
|
"""
|
||||||
|
# Issue https://github.com/nim-lang/Nim/issues/4262
|
||||||
|
import asyncdispatch, times
|
||||||
|
|
||||||
|
proc foo(): Future[int] {.async.} =
|
||||||
|
return 1
|
||||||
|
|
||||||
|
proc bar(): Future[int] {.async.} =
|
||||||
|
return await foo()
|
||||||
|
|
||||||
|
let start = epochTime()
|
||||||
|
let barFut = bar()
|
||||||
|
|
||||||
|
while not barFut.finished:
|
||||||
|
poll(2000)
|
||||||
|
|
||||||
|
echo(epochTime() - start < 1.0)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue