You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Alfis/src/commons/eventbus.rs

24 lines
534 B
Rust

use std::sync::Mutex;
use lazy_static::lazy_static;
use uuid::Uuid;
use crate::event::Event;
use crate::simplebus::Bus;
lazy_static! {
static ref STATIC_BUS: Mutex<Bus<Event>> = Mutex::new(Bus::new());
}
pub fn register<F>(closure: F) -> Uuid
where F: FnMut(&Uuid, Event) -> bool + Send + Sync + 'static {
STATIC_BUS.lock().unwrap().register(Box::new(closure))
}
pub fn unregister(uuid: &Uuid) {
STATIC_BUS.lock().unwrap().unregister(uuid);
}
pub fn post(event: Event) {
STATIC_BUS.lock().unwrap().post(event);
}