Implements `asyncdispatch.getIoHandler` and assert on nil futures.

This commit is contained in:
Dominik Picheta 2017-11-24 16:30:56 +00:00
commit 325e4520ec
3 changed files with 12 additions and 0 deletions

View file

@ -23,6 +23,9 @@
in the async dispatcher. in the async dispatcher.
- Implemented an `accept` proc that works on a `SocketHandle` in - Implemented an `accept` proc that works on a `SocketHandle` in
``nativesockets``. ``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 - The overloading rules changed slightly so that constrained generics are
preferred over unconstrained generics. (Bug #6526) preferred over unconstrained generics. (Bug #6526)
- It is now possible to forward declare object types so that mutually - It is now possible to forward declare object types so that mutually

View file

@ -262,6 +262,11 @@ when defined(windows) or defined(nimdoc):
setGlobalDispatcher(newDispatcher()) setGlobalDispatcher(newDispatcher())
result = gDisp 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.} = proc register*(fd: cint | SocketHandle | AsyncFD): AsyncFD {.discardable.} =
## Registers ``fd`` with the dispatcher. ## Registers ``fd`` with the dispatcher.
## ##
@ -1103,6 +1108,9 @@ else:
setGlobalDispatcher(newDispatcher()) setGlobalDispatcher(newDispatcher())
result = gDisp result = gDisp
proc getIoHandler*(disp: PDispatcher): Selector[AsyncData] =
return disp.selector
proc register*(fd: cint | SocketHandle | AsyncFD): AsyncFD {.discardable.} = proc register*(fd: cint | SocketHandle | AsyncFD): AsyncFD {.discardable.} =
let p = getGlobalDispatcher() let p = getGlobalDispatcher()
when fd is AsyncFD: when fd is AsyncFD:

View file

@ -281,6 +281,7 @@ proc asyncCheck*[T](future: Future[T]) =
## finished with an error. ## finished with an error.
## ##
## This should be used instead of ``discard`` to discard void futures. ## This should be used instead of ``discard`` to discard void futures.
assert(not future.isNil, "Future is nil")
future.callback = future.callback =
proc () = proc () =
if future.failed: if future.failed: