sync_utils/worker_pool/
mod.rs1pub mod bounded;
2pub mod bounded_blocking;
3pub mod unbounded;
4
5use std::time::Duration;
6
7pub const ZERO_DUARTION: Duration = Duration::from_secs(0);
8
9#[async_trait]
10pub trait Worker<M: Send + Sized + Unpin + 'static>: Send + Sync + Unpin + 'static {
11 #[inline]
12 async fn init(&mut self) -> Result<(), ()> {
13 Ok(())
14 }
15
16 async fn run(&mut self, msg: M);
17
18 fn on_exit(&self) {}
19}
20
21pub trait WorkerPoolImpl<M: Send + Sized + Unpin + 'static, W: Worker<M>>:
22 Send + Sync + Sized + 'static
23{
24 fn spawn(&self) -> W;
25}
26
27pub trait WorkerPoolInf<M: Send + Sized + Unpin + 'static>: Send + Sync {
28 fn submit(&self, msg: M) -> Option<M>;
29}
30
31#[async_trait]
32pub trait WorkerPoolAsyncInf<M: Send + Sized + Unpin + 'static>: Send + Sync {
33 async fn submit(&self, msg: M) -> Option<M>;
34
35 fn try_submit(&self, msg: M) -> Option<M>;
36}