A low-level library to build event driven applications. The core of the
library is [poll], which polls multiple event sources for readiness
events. Based on these readiness events the application will continue, e.g.
by running a Future.
A number of readiness event sources are provided:
- [
OsQueue]: a readiness event queue backed by the OS (epoll or kqueue). - [
Queue]: a single threaded, user space queue. - [
Timers]: a single threaded, deadline based readiness queue.
Getting started
Using the crate starts by creating one or more [event::Source]s.
# use ;
#
As the name suggest event::Sources are the sources of readiness events,
these can be polled for readiness events (we'll get back to this later).
This crate provides three [OsQueue], [Queue] and [Timers]. But as
event::Source is a trait it can be implemented outside of this crate.
Next an [event::Sink] is required, this used to store the readiness events
from the event sources.
// `Vec`tor implements `event::Sink`.
let events = Vecnew;
# ;
Just like event::Source, event::Sink is also a trait. When, for example,
building some kind of runtime event::Source can be directly implemented on
the scheduler type and instead of adding an [Event] to a collection it
will schedule a process/Future/task to run. For convenience Vectors
also implement event::Sink.
Both the event::Sources and event::Sink should only be created once and
reused in each call to [poll]. After we created both we can start
polling the event::Sources.
# use io;
# use Duration;
# use ;
#
After the event::Sources are polled our event::Sink will be filled with
readiness events, if there are any. These can be used to continue
processing. Stick all the above in a loop and you've got yourself an event
loop, congratulations!
use io;
use Duration;
use ;
#
Examples
More complete examples of how to use the crate can be found in the examples directory of the source code (on GitHub).