2023-10-25 21:43:39 +04:00
|
|
|
#![feature(impl_trait_in_assoc_type)]
|
|
|
|
|
2023-10-24 14:23:22 +04:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2023-10-25 21:43:39 +04:00
|
|
|
use messagebus::{Builder, Bus, Error, Handler, IntoMessage, Message};
|
2023-10-24 14:23:22 +04:00
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Msg(pub i32);
|
|
|
|
impl Message for Msg {}
|
|
|
|
|
|
|
|
pub struct Processor {
|
|
|
|
state: i32,
|
|
|
|
}
|
|
|
|
|
2023-10-25 21:43:39 +04:00
|
|
|
impl Handler<Msg> for Processor {
|
|
|
|
type Result = ();
|
|
|
|
type IntoMessage = impl IntoMessage<Self::Result>;
|
|
|
|
type HandleFut<'a> = impl futures::Future<Output = Result<Self::IntoMessage, Error>> + 'a;
|
|
|
|
type FinalizeFut<'a> = impl futures::Future<Output = Result<(), Error>> + 'a;
|
|
|
|
|
|
|
|
fn handle(&mut self, msg: Msg, _stream_id: u32, _task_id: u32) -> Self::HandleFut<'_> {
|
|
|
|
async move { Ok(()) }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn finalize<'a>(self) -> Self::FinalizeFut<'a> {
|
|
|
|
async move { Ok(()) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ProcSpawner;
|
|
|
|
impl Builder<Msg> for ProcSpawner {
|
|
|
|
type Context = Processor;
|
|
|
|
type BuildFut<'a> = impl futures::Future<Output = Result<Self::Context, Error>> + 'a;
|
|
|
|
|
|
|
|
fn build(&self, stream_id: u32, _task_id: u32) -> Self::BuildFut<'_> {
|
|
|
|
async move {
|
|
|
|
Ok(Processor {
|
|
|
|
state: stream_id as _,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-24 14:23:22 +04:00
|
|
|
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();
|
2023-10-25 21:43:39 +04:00
|
|
|
bus.register(ProcSpawner).await;
|
2023-10-24 14:23:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
run().await
|
|
|
|
}
|