diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2016-12-30 11:06:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-30 11:06:38 +0000 |
commit | 09b6d8c0ca5f9b5590e58d90b987975f36df8dd6 (patch) | |
tree | 7d03896d1250a72d02ba3e4a39c4840ff1749768 /lib/pure | |
parent | cfea779e23bbcd586044cfe7be412dc87aad7c50 (diff) | |
parent | 8e71949b785ca2b2bc61d0f95c5ac88fa87621fe (diff) | |
download | Nim-09b6d8c0ca5f9b5590e58d90b987975f36df8dd6.tar.gz |
Merge pull request #5163 from vegansk/5155-async
Adds pending operations presence check function to asyncdispatch, fixes #5155
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/asyncdispatch.nim | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 1367bc411..b72596060 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -254,8 +254,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, @@ -1056,8 +1062,15 @@ else: newCBs.add(cb) callbacks = newCBs & callbacks + proc hasPendingOperations*(): bool = + let p = getGlobalDispatcher() + p.selector.len != 0 or p.timers.len != 0 or p.callbacks.len != 0 + proc poll*(timeout = 500) = let p = getGlobalDispatcher() + if p.selector.len == 0 and p.timers.len == 0 and p.callbacks.len == 0: + raise newException(ValueError, + "No handles or timers registered in dispatcher.") if p.selector.len > 0: for info in p.selector.select(p.adjustedTimeout(timeout)): |