Add pending operations presence check function, fixes #5155

This commit is contained in:
Anatoly Galiulin 2016-12-29 11:22:50 +07:00
commit 8e71949b78
3 changed files with 46 additions and 2 deletions

View file

@ -231,8 +231,14 @@ when defined(windows) or defined(nimdoc):
"Operation performed on a socket which has not been registered with" &
" the dispatcher yet.")
proc hasPendingOperations*(): bool =
## Returns `true` if the global dispatcher has pending operations.
let p = getGlobalDispatcher()
p.handles.len != 0 or p.timers.len != 0 or p.callbacks.len != 0
proc poll*(timeout = 500) =
## Waits for completion events and processes them.
## Waits for completion events and processes them. Raises ``ValueError``
## if there are no pending operations.
let p = getGlobalDispatcher()
if p.handles.len == 0 and p.timers.len == 0 and p.callbacks.len == 0:
raise newException(ValueError,
@ -1182,6 +1188,10 @@ else:
raise newException(ValueError, "File descriptor not registered.")
p.selector.updateHandle(fd.SocketHandle, newEvents)
proc hasPendingOperations*(): bool =
let p = getGlobalDispatcher()
not p.selector.isEmpty() or p.timers.len != 0 or p.callbacks.len != 0
proc poll*(timeout = 500) =
var keys: array[64, ReadyKey[AsyncData]]