1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use tokio::sync::mpsc;
use crate::{handle::Handle, Processor};
pub mod simple;
#[async_trait::async_trait]
pub trait Executor<P>: Send + 'static
where
P: Processor,
{
async fn run(&mut self, receiver: mpsc::UnboundedReceiver<P::Command>) -> Result<(), P::Error>;
fn spawn(self) -> Handle<P>
where
Self: Sized,
{
let (sender, receiver) = mpsc::unbounded_channel();
let task = tokio::spawn(async move {
let mut executor = self;
executor.run(receiver).await.err().unwrap()
});
Handle::new(task, sender)
}
}