41 lines
768 B
Rust
41 lines
768 B
Rust
|
use std::sync::Arc;
|
||
|
|
||
|
use messagebus::{Bus, Error, Message};
|
||
|
|
||
|
#[derive(Debug, Clone)]
|
||
|
pub struct Msg(pub i32);
|
||
|
impl Message for Msg {}
|
||
|
|
||
|
pub struct Processor {
|
||
|
state: i32,
|
||
|
}
|
||
|
|
||
|
impl Processor {
|
||
|
pub async fn spawn(sid: u32) -> Result<(usize, Self), Error> {
|
||
|
Ok((4, Self { state: 0 }))
|
||
|
}
|
||
|
|
||
|
pub async fn handler_msg(self: Arc<Self>, sid: u32, tid: u32, msg: Msg) -> Result<(), Error> {
|
||
|
Ok(())
|
||
|
}
|
||
|
|
||
|
pub async fn finalize_msg_handler(self: Arc<Self>, sid: u32) -> Result<(), Error> {
|
||
|
Ok(())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async fn run() {
|
||
|
let bus = Bus::new();
|
||
|
bus.register(
|
||
|
4,
|
||
|
Processor::spawn,
|
||
|
Processor::handler_msg,
|
||
|
Processor::finalize_msg_handler,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
#[tokio::main]
|
||
|
async fn main() {
|
||
|
run().await
|
||
|
}
|