pub struct ActorManager<A: AsyncActor, const E: usize = 256> { /* private fields */ }Expand description
子 actor 管理器。
ActorManager 本身实现了 AsyncActor,因此可以像普通 actor 一样被 AsyncActor::spawn
启动和持有。
它管理一组同类型的子 actor,对外提供:
- 启动/停止子 actor
- 向指定子 actor 转发命令
- 聚合所有子 actor 的状态、进度和事件
§类型参数
A: 子 actor 的类型,必须实现AsyncActor。E: 管理器事件通道(broadcast)的容量。
§示例
let manager = ActorManager::<MyActor>::new();
let handle = manager.spawn();
// 启动子 actor,返回分配的 id
let (id_tx,id_rx) = tokio::sync::oneshot::channel();
handle.send_cmd(ManagerCmd::SpawnActor{actor:MyActor,id_tx:Some(id_tx)}).unwrap();
let id = id_rx.await.unwrap();
Implementations§
Source§impl<A: AsyncActor, const E: usize> ActorManager<A, E>
impl<A: AsyncActor, const E: usize> ActorManager<A, E>
Sourcepub fn new() -> Self
pub fn new() -> Self
创建一个空的 ActorManager。
初始时不管理任何子 actor,需要启动后通过 ManagerCmd::SpawnActor 添加。
pub fn set_update_interval(&mut self, interval: Duration)
Trait Implementations§
Source§impl<A: AsyncActor, const E: usize> ActorCore for ActorManager<A, E>
impl<A: AsyncActor, const E: usize> ActorCore for ActorManager<A, E>
Source§const EVENT_CAPACITY: usize = E
const EVENT_CAPACITY: usize = E
actor 的事件通道容量
Source§type Cmd = ManagerCmd<A>
type Cmd = ManagerCmd<A>
actor 命令枚举 Read more
Source§type Progress = ManagerProgress<<A as ActorCore>::Progress>
type Progress = ManagerProgress<<A as ActorCore>::Progress>
actor 里的高频状态,如果没有高频进度时,用
type Progress = ();。fn init_state_and_progress(&self) -> (Self::State, Self::Progress)
Source§fn channel(
init_state: Self::State,
init_progress: Self::Progress,
) -> (ActorContext<Self>, ActorHandle<Self>)
fn channel( init_state: Self::State, init_progress: Self::Progress, ) -> (ActorContext<Self>, ActorHandle<Self>)
创建 actor 的通道。
ActorContext 是 actor 的后台端,ActorHandle 是 actor 的控制端。
Source§impl<A: AsyncActor, const E: usize> AsyncActor for ActorManager<A, E>
impl<A: AsyncActor, const E: usize> AsyncActor for ActorManager<A, E>
Source§impl<A: AsyncActor, const E: usize> Default for ActorManager<A, E>
impl<A: AsyncActor, const E: usize> Default for ActorManager<A, E>
Auto Trait Implementations§
impl<A, const E: usize = 256> !Freeze for ActorManager<A, E>
impl<A, const E: usize> RefUnwindSafe for ActorManager<A, E>where
HashMap<usize, ActorHandle<A>>: RefUnwindSafe,
ManagerState<<A as ActorCore>::State>: RefUnwindSafe,
ManagerProgress<<A as ActorCore>::Progress>: RefUnwindSafe,
impl<A, const E: usize> Send for ActorManager<A, E>where
HashMap<usize, ActorHandle<A>>: Send,
ManagerState<<A as ActorCore>::State>: Send,
ManagerProgress<<A as ActorCore>::Progress>: Send,
impl<A, const E: usize> Sync for ActorManager<A, E>where
HashMap<usize, ActorHandle<A>>: Sync,
ManagerState<<A as ActorCore>::State>: Sync,
ManagerProgress<<A as ActorCore>::Progress>: Sync,
impl<A, const E: usize> Unpin for ActorManager<A, E>where
HashMap<usize, ActorHandle<A>>: Unpin,
ManagerState<<A as ActorCore>::State>: Unpin,
ManagerProgress<<A as ActorCore>::Progress>: Unpin,
impl<A, const E: usize> UnsafeUnpin for ActorManager<A, E>where
HashMap<usize, ActorHandle<A>>: UnsafeUnpin,
ManagerState<<A as ActorCore>::State>: UnsafeUnpin,
ManagerProgress<<A as ActorCore>::Progress>: UnsafeUnpin,
impl<A, const E: usize> UnwindSafe for ActorManager<A, E>where
HashMap<usize, ActorHandle<A>>: UnwindSafe,
ManagerState<<A as ActorCore>::State>: UnwindSafe,
ManagerProgress<<A as ActorCore>::Progress>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more