Crate mrogalski_looper [−] [src]
Clean abstraction for a single-threaded event loop. Built as a lightweight wrapper around the std::sync::mpsc
package.
Example usage:
use mrogalski_looper::{Handler, Sender, run}; struct ExampleHandler { data: Vec<i32>, } impl Handler<i32> for ExampleHandler { // Invoked right after the `run` function is called. fn start(&mut self, sender: Sender<i32>) { for elem in vec![1, 2, 3] { sender.send(elem.clone()).unwrap(); } } // Called for every `event` sent to the `sender`. fn handle(&mut self, i: i32) -> bool { self.data.push(i); true } // Called after last event is processed or an error occurs. fn end(self) { assert_eq!(self.data, vec![1, 2, 3]); } } // Blocks the current thread until all events are processed. run(ExampleHandler { data: vec![] });
Reexports
pub use std::sync::mpsc::Sender; |
Traits
Handler |
Handles events sent to the event loop. |
Functions
run |
Runs the event loop on the current thread. |