calloop
Calloop, a Callback-based Event Loop
This crate provides an EventLoop
type, which is a small abstraction
over epoll or kaqueue for unix systems. The main difference between this crate
and other traditional rust event loops is that it is based on callbacks:
you can register several event sources, each being associated with a callback
closure that will be invoked whenever the associated event source generates
events.
This crate was initially an implementation detail of wayland-server
, and has been
split-off for reuse. I expect it to be more useful for GUI programs or graphical
servers (like wayland-based apps) than performance critial networking code, which are
more versed towards tokio
and async-await. It mostly shines in the conception of
modular infrastructures, allowing different modules to use the same event loop without
needing to know about each other.
How to use it
extern crate calloop;
use Duration;
Event source types
This crate provides some adapters for common event sources such as:
- MPSC channels
- Timers
- unix signals
As well as generic handler for monitoring file desriptors.
It is also possible to insert "idle" callbacks. These callbacks represent computations that
need to be done at some point, but are not as urgent as processing the events. These callbacks
are stored and then executed during EventLoop::dispatch(..)
, once all events from the sources
have been processed.
Custom event sources
You can create custom event sources that can inserted in the event loop by
implementing the EventSource
trait.
License: MIT