Chronos - An efficient library for asynchronous programming https://status-im.github.io/nim-chronos/docs/chronos
Go to file
Bruno Škvorc 90f2a50dda
Update README.md
2019-01-02 14:53:00 +01:00
asyncdispatch2 Fix removeReader/removeWriter can produce SIGSEGV. 2018-12-12 13:07:41 +02:00
tests fixes StreamTransport readOnce bug 2018-11-20 13:58:25 +07:00
.appveyor.yml Remove cache dependency on appveyor.yml. 2018-11-08 00:31:20 +02:00
.travis.yml ci: update 2018-09-04 20:29:34 -06:00
LICENSE-APACHEv2 Initial commit 2018-05-16 11:22:34 +03:00
LICENSE-MIT Initial commit 2018-05-16 11:22:34 +03:00
README.md Update README.md 2019-01-02 14:53:00 +01:00
asyncdispatch2.nim Export fastEpochTime(). 2018-07-25 21:42:08 +03:00
asyncdispatch2.nimble Fix removeReader/removeWriter can produce SIGSEGV. 2018-12-12 13:07:41 +02:00

README.md

Asyncdispatch hard fork

Build Status (Travis) Windows build status (Appveyor) License: Apache License: MIT Stability: experimental

Core differences between asyncdispatch and asyncdispatch2

  1. Unified callback type CallbackFunc:

    Current version of asyncdispatch uses many types of callbacks:

    • proc () is used in callSoon() callbacks and Future[T] completion callbacks.
    • proc (fut: Future[T]) is used in Future[T] completion callbacks.
    • proc (fd: AsyncFD, bytesTransferred: Dword, errcode: OSErrorCode) is used in Windows IO completion callbacks.
    • proc (fd: AsyncFD): bool is used in Unix IO event callbacks.

    Such a large number of different types creates big problems in the storage and processing of callbacks and in interaction between callbacks. Lack of ability to pass custom user data to a callback also creates difficulties and inefficiency with passing custom, user-defined data needed for using closures (one more allocation).

    To resolve this issue, we have introduced a unified callback type, CallbackFunc:

    type
      CallbackFunc* = proc (arg: pointer = nil) {.gcsafe.}
    

    Also, one more type was introduced for the callback storage, AsyncCallback:

    type
        AsyncCallback* = object
          function*: CallbackFunc
          udata*: pointer
    
  2. The order of Future[T] completion callbacks:

    Current version of asyncdispatch processes Future[T] completion callbacks in reverse order, but asyncdispatch2 schedules callbacks in forward order: https://github.com/nim-lang/Nim/issues/7197

  3. Changed the behavior of OS descriptor event callbacks:

    For some unknown reason, the current version of asyncdispatch uses seq[T] to hold a list of descriptor event listeners. However, in the asynchronous environment, there is no need for a list of event listeners. In asyncdispatch2, there is only one place for one READ listener and one place for one WRITE listener.

  4. Removed the default timeout value for the poll() procedure, which allows incorrect usage of asyncdispatch and produces 500-ms timeouts in correct usage.

  5. Changed the behavior of the scheduler in the poll() procedure, and fixed the following issues:

  6. Asyncdispatch2 no longer uses epochTime(); instead, it uses the fastest time primitives for a specific OS, fastEpochTime(). Also, because MacOS supports only a millisecond resolution in kqueue, sub-millisecond resolution is not needed. For details, see https://github.com/nim-lang/Nim/issues/3909.

  7. Removed all IO primitives (recv(), recvFrom(), connect(), accept(), send(), and sendTo()) from the public API, and moved all their functionality into Transports.

  8. Introduced an addTimer() / removeTimer() callback interface.

  9. Introduced removeReader() for addReader() and removeWriter() for addWriter().

  10. Changed the behavior of the addReader(), addWriter(), and addTimer() callbacks. Now, only the explicit removal of the callbacks must be supplied via removeReader(), removeWriter(), and removeTimer().

  11. Added the support for the cross-platform sendfile() operation.

  12. Removed the expensive AsyncEvent and the support for hardware timers and addProcess. addProcess will be implemented as SubprocessTransport, while hardware-based AsyncEvent will be renamed to ThreadAsyncEvent.

  13. Added cheap synchronization primitives: AsyncLock, AsyncEvent, and AsyncQueue[T].

Documentation

You can find more documentation, notes and examples in Wiki.

Installation

You can use Nim official package manager nimble to install asyncdispatch2. The most recent version of the library can be installed via:

$ nimble install https://github.com/status-im/nim-asyncdispatch2.git

TODO

  • Pipe/Subprocess Transports.
  • Multithreading Stream/Datagram servers
  • Future[T] cancelation

License

Licensed and distributed under either of

or

at your option. This file may not be copied, modified, or distributed except according to those terms.