zestors/actor_reference/
child_type.rs1#[allow(unused)]
2use crate::all::*;
3use tokio::task::JoinHandle;
4
5pub trait ChildType {
9 type JoinHandles<E: Send + 'static>: Send + 'static;
10 fn abort<E: Send + 'static>(handles: &Self::JoinHandles<E>);
11 fn is_finished<E: Send + 'static>(handles: &Self::JoinHandles<E>) -> bool;
12}
13
14#[derive(Debug)]
16pub struct SingleProcess;
17
18impl ChildType for SingleProcess {
19 type JoinHandles<E: Send + 'static> = JoinHandle<E>;
20
21 fn abort<E: Send + 'static>(handles: &Self::JoinHandles<E>) {
22 handles.abort()
23 }
24
25 fn is_finished<E: Send + 'static>(handles: &Self::JoinHandles<E>) -> bool {
26 handles.is_finished()
27 }
28}
29
30#[derive(Debug)]
32pub struct MultiProcess;
33
34impl ChildType for MultiProcess {
35 type JoinHandles<E: Send + 'static> = Vec<JoinHandle<E>>;
36
37 fn abort<E: Send + 'static>(handles: &Self::JoinHandles<E>) {
38 for handle in handles {
39 handle.abort()
40 }
41 }
42
43 fn is_finished<E: Send + 'static>(handles: &Self::JoinHandles<E>) -> bool {
44 handles.iter().all(|handle| handle.is_finished())
45 }
46}