Crates.io | mio-wakeq |
lib.rs | mio-wakeq |
version | 0.1.0 |
source | src |
created_at | 2024-11-15 22:50:57.004815 |
updated_at | 2024-11-15 22:50:57.004815 |
description | mio support for custom event queue via Waker |
homepage | |
repository | https://github.com/okedax/mio-wakeq |
max_upload_size | |
id | 1449713 |
size | 18,981 |
A simple custom event delivery mechanism based on mio's Waker
functionality for mio
-based systems. mio
's Poll
is limited to a single Waker
, which restricts it to handling only one type of external event.
However, mio-wakeq
allows multiple events to be managed and exposed through a single Waker
within the same Poll
instance.
use mio::{Events, Poll, Token};
use mio_wakeq::{EventId, EventQ, WakeQ};
const WAKER: Token = Token(0);
const EVENT0: EventId = EventId(0);
let mut poll = Poll::new().unwrap();
let wakeq = EventQ::new(&poll, WAKER, 8).unwrap();
let event_sender = wakeq.get_sender();
std::thread::spawn(move || {
event_sender.trigger_event(EVENT0);
});
let mut events = Events::with_capacity(32);
poll.poll(&mut events, None).unwrap();
for event in events.iter() {
match event.token() {
WAKER => {
for wev in wakeq.triggered_events() {
assert_eq!(wev, EVENT0);
}
}
_ => unimplemented!(),
}
}