rooper 0.1.0

A simple looper in rust.
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented1 out of 1 items with examples
  • Size
  • Source code size: 9.73 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.4 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • yehuohan

looper

基于rust实现的消息事件循环系统。

  • looper模块负责用户消息的插入;
  • handler模块负责处理用户消息;

基本原理

looper模块将用户的所有消息,按照UNIX时间顺序,插入到链表中; handler模块从链表中,取出已经到时间的消息进行处理。

示例

use rooper::{Looper, LooperMsg};

struct ExMsg {
    val: i32,
}

impl LooperMsg for ExMsg {
    fn handle_message(self) {
        println!("msg val: {}", self.val);
    }
}

fn main() {
    let mut lp = Looper::new();
    lp.send_msg_delay(ExMsg {val: 4}, std::time::Duration::from_millis(400));
    lp.send_msg_delay(ExMsg {val: 3}, std::time::Duration::from_millis(600));
    lp.send_msg_delay(ExMsg {val: 2}, std::time::Duration::from_millis(800));
    lp.send_msg_delay(ExMsg {val: 1}, std::time::Duration::from_millis(1000));
    lp.send_msg_delay(ExMsg {val: 5}, std::time::Duration::from_millis(200));

    std::thread::sleep(std::time::Duration::from_secs(2));
    lp.terminate();
}