summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2017-11-24 16:30:56 +0000
committerDominik Picheta <dominikpicheta@gmail.com>2017-11-24 16:30:56 +0000
commit325e4520ec74cd49a21c389bb2d137a74536f062 (patch)
tree8f378c0e0a857b3c42b57df5fb7be5b98e4aa3ea
parente5a27c96fbd8a3bdd48b1974595381c1a335aaa5 (diff)
downloadNim-325e4520ec74cd49a21c389bb2d137a74536f062.tar.gz
Implements ``asyncdispatch.getIoHandler`` and assert on nil futures.
-rw-r--r--changelog.md3
-rw-r--r--lib/pure/asyncdispatch.nim8
-rw-r--r--lib/pure/asyncfutures.nim1
3 files changed, 12 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md
index a9212efbd..847a36d84 100644
--- a/changelog.md
+++ b/changelog.md
@@ -23,6 +23,9 @@
   in the async dispatcher.
 - Implemented an `accept` proc that works on a `SocketHandle` in
   ``nativesockets``.
+- Implemented ``getIoHandler`` proc in the ``asyncdispatch`` module that allows
+  you to retrieve the underlying IO Completion Port or ``Selector[AsyncData]``
+  object in the specified dispatcher.
 - The overloading rules changed slightly so that constrained generics are
   preferred over unconstrained generics. (Bug #6526)
 - It is now possible to forward declare object types so that mutually
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim
index 7211fabc7..cee692980 100644
--- a/lib/pure/asyncdispatch.nim
+++ b/lib/pure/asyncdispatch.nim
@@ -262,6 +262,11 @@ when defined(windows) or defined(nimdoc):
       setGlobalDispatcher(newDispatcher())
     result = gDisp
 
+  proc getIoHandler*(disp: PDispatcher): Handle =
+    ## Returns the underlying IO Completion Port handle (Windows) or selector
+    ## (Unix) for the specified dispatcher.
+    return disp.ioPort
+
   proc register*(fd: cint | SocketHandle | AsyncFD): AsyncFD {.discardable.} =
     ## Registers ``fd`` with the dispatcher.
     ##
@@ -1103,6 +1108,9 @@ else:
       setGlobalDispatcher(newDispatcher())
     result = gDisp
 
+  proc getIoHandler*(disp: PDispatcher): Selector[AsyncData] =
+    return disp.selector
+
   proc register*(fd: cint | SocketHandle | AsyncFD): AsyncFD {.discardable.} =
     let p = getGlobalDispatcher()
     when fd is AsyncFD:
diff --git a/lib/pure/asyncfutures.nim b/lib/pure/asyncfutures.nim
index bebd19611..8941dca6e 100644
--- a/lib/pure/asyncfutures.nim
+++ b/lib/pure/asyncfutures.nim
@@ -281,6 +281,7 @@ proc asyncCheck*[T](future: Future[T]) =
   ## finished with an error.
   ##
   ## This should be used instead of ``discard`` to discard void futures.
+  assert(not future.isNil, "Future is nil")
   future.callback =
     proc () =
       if future.failed: