pub struct ActorManager<A: Actor> { /* private fields */ }Expand description
子 actor 管理器。
ActorManager 本身实现了 Actor trait,因此可以像普通 actor 一样被 spawn 和持有。
它管理一组同类型的子 actor,对外提供:
- 启动/停止子 actor
- 向指定子 actor 转发命令
- 聚合所有子 actor 的状态、进度和事件
§类型参数
A: 子 actor 的类型,必须实现Actortrait。
§示例
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)}).await.unwrap();
let id = id_rx.await.unwrap();Implementations§
Source§impl<A: Actor> ActorManager<A>
impl<A: Actor> ActorManager<A>
Sourcepub fn new() -> Self
pub fn new() -> Self
创建一个空的 ActorManager。
初始时不管理任何子 actor,需要启动后通过 ManagerCmd::SpawnActor 添加。
Trait Implementations§
Source§impl<A: Actor> Actor for ActorManager<A>
impl<A: Actor> Actor for ActorManager<A>
Source§type Cmd = ManagerCmd<A>
type Cmd = ManagerCmd<A>
actor 命令枚举 Read more
Source§type Progress = ManagerProgress<<A as Actor>::Progress>
type Progress = ManagerProgress<<A as Actor>::Progress>
actor 里的高频状态,如果没有高频进度时,用
type Progress = ();。fn init_state_and_progress(&self) -> (Self::State, Self::Progress)
Source§fn run(
self,
context: ActorContext<Self>,
) -> impl Future<Output = ()> + Send + 'static
fn run( self, context: ActorContext<Self>, ) -> impl Future<Output = ()> + Send + 'static
actor的主要循环 Read more
Source§const CMD_CAPACITY: usize = 16
const CMD_CAPACITY: usize = 16
actor 的命令通道容量
Source§const EVENT_CAPACITY: usize = 16
const EVENT_CAPACITY: usize = 16
actor 的事件通道容量
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§fn spawn(self) -> ActorHandle<Self>
fn spawn(self) -> ActorHandle<Self>
启动 actor。 Read more
Auto Trait Implementations§
impl<A> !Freeze for ActorManager<A>
impl<A> RefUnwindSafe for ActorManager<A>where
HashMap<usize, ActorHandle<A>>: RefUnwindSafe,
ManagerState<<A as Actor>::State>: RefUnwindSafe,
ManagerProgress<<A as Actor>::Progress>: RefUnwindSafe,
impl<A> Send for ActorManager<A>where
HashMap<usize, ActorHandle<A>>: Send,
ManagerState<<A as Actor>::State>: Send,
ManagerProgress<<A as Actor>::Progress>: Send,
impl<A> Sync for ActorManager<A>where
HashMap<usize, ActorHandle<A>>: Sync,
ManagerState<<A as Actor>::State>: Sync,
ManagerProgress<<A as Actor>::Progress>: Sync,
impl<A> Unpin for ActorManager<A>where
HashMap<usize, ActorHandle<A>>: Unpin,
ManagerState<<A as Actor>::State>: Unpin,
ManagerProgress<<A as Actor>::Progress>: Unpin,
impl<A> UnsafeUnpin for ActorManager<A>where
HashMap<usize, ActorHandle<A>>: UnsafeUnpin,
ManagerState<<A as Actor>::State>: UnsafeUnpin,
ManagerProgress<<A as Actor>::Progress>: UnsafeUnpin,
impl<A> UnwindSafe for ActorManager<A>where
HashMap<usize, ActorHandle<A>>: UnwindSafe,
ManagerState<<A as Actor>::State>: UnwindSafe,
ManagerProgress<<A as Actor>::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