Closed gqf2008 closed 2 years ago
发布订阅模式消息总线
static BUS: Bus = Bus::new();
enum Event { Key(u8), Mouse(isize, isize), } BUS.subscribe("ev.key", |topic, ev| match ev { Event::Key(code) => { sprintln!("{} {:?}", topic, ev); } _ => {} }); BUS.subscribe("ev.mouse", |topic, ev| match ev { Event::Mouse(x, y) => { sprintln!("{} {:?}", topic, ev); } _ => {} }); TaskBuilder::new().name("events").spawn(move || loop { BUS.event("ev.key", Event::Key(8)); xtask::sleep_ms(1000); }); TaskBuilder::new().name("events").spawn(move || loop { BUS.event("ev.mouse", Event::Mouse(8378, 10036)); xtask::sleep_ms(500); });
发布订阅模式消息总线
static BUS: Bus = Bus::new();
[derive(Debug, Clone, Copy)]