#mio #waker #async #event-queue

mio-wakeq

mio support for custom event queue via Waker

1 unstable release

new 0.1.0 Nov 15, 2024

#668 in Asynchronous

Download history 89/week @ 2024-11-11

89 downloads per month

MIT license

11KB
136 lines

mio-wakeq

CI crates.io docs.rs Rust Version License

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.

example

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!(),
    }
}

Dependencies

~0.3–7MB
~44K SLoC