zmq/asynczmq

Types

AsyncZPollCB = proc (x: ZSocket) {....gcsafe.}
AsyncZPoller = object
  cb*: seq[AsyncZPollCB]
  zpoll*: ZPoller
Experimental type to use zmq.poll() with Nim's async dispatch loop

Procs

proc `=destroy`(obj: AsyncZPoller) {....raises: [], tags: [TimeEffect, RootEffect],
                                     forbids: [].}
proc initZPoller(args: openArray[tuple[item: ZConnection, cb: AsyncZPollCB]];
                 event: cshort): AsyncZPoller {....raises: [], tags: [],
    forbids: [].}
Init a ZPoller with all items on the same event The callback should use non-blocking proc waitForReceive with strictly positive timeout or tryReceive or c.receive(DONTWAIT)
proc initZPoller(poller: sink ZPoller; cb: AsyncZPollCB): AsyncZPoller {.
    ...raises: [], tags: [], forbids: [].}
The callback should use non-blocking proc such waitForReceive or tryReceive or c.receive(DONTWAIT)
proc len(poller: AsyncZPoller): int {....raises: [], tags: [], forbids: [].}
proc pollAsync(poller: AsyncZPoller; timeout: int = 2): Future[int] {.
    ...raises: [ValueError, Exception, OSError], tags: [TimeEffect, RootEffect],
    forbids: [].}
Experimental API. Poll all the ZConnection and execute an async CB when event occurs. The callback should use non-blocking proc waitForReceive with strictly positive timeout or tryReceive or c.receive(DONTWAIT)
proc receiveAsync(conn: ZConnection): Future[string] {.
    ...raises: [ZmqError, OSError, ValueError, Exception], tags: [RootEffect],
    forbids: [].}

Similar to receive(), but receiveAsync() allows other async tasks to run. receiveAsync() allows other async tasks to run in those cases.

This will not work in some case because it depends on ZMQ_FD which is not necessarily the 'true' FD of the socket

See https://github.com/zeromq/libzmq/issues/2941 and https://github.com/zeromq/pyzmq/issues/1411

proc register(poller: var AsyncZPoller; conn: ZConnection; event: int;
              cb: AsyncZPollCB) {....raises: [], tags: [], forbids: [].}
Register ZConnection The callback should ideally use non-blocking proc such waitForReceive or tryReceive or c.receive(DONTWAIT)
proc register(poller: var AsyncZPoller; item: ZPollItem; cb: AsyncZPollCB) {.
    ...raises: [], tags: [], forbids: [].}
Register ZConnection. The callback should use non-blocking proc waitForReceive with strictly positive timeout or tryReceive or c.receive(DONTWAIT)
proc register(poller: var AsyncZPoller; sock: ZSocket; event: int;
              cb: AsyncZPollCB) {....raises: [], tags: [], forbids: [].}
Register ZSocket function The callback should ideally use non-blocking proc such waitForReceive or tryReceive or c.receive(DONTWAIT)
proc sendAsync(conn: ZConnection; msg: string;
               flags: ZSendRecvOptions = DONTWAIT): Future[void] {.
    ...raises: [ZmqError, OSError, Exception], tags: [RootEffect], forbids: [].}

send() is blocking for some connection types (e.g. PUSH, DEALER). sendAsync() allows other async tasks to run in those cases.

This will not work in some case because it depends on ZMQ_FD which is not necessarily the 'true' FD of the socket

See https://github.com/zeromq/libzmq/issues/2941 and https://github.com/zeromq/pyzmq/issues/1411