pub struct ActorHandle<A: Actor> { /* private fields */ }Expand description
actor 的控制端。
由 Actor::channel 创建,通常由外部控制方持有。
用于发送命令、读取状态/进度、订阅事件,以及注册异步监听。
§示例
let (context, handle) = MyActor::channel( (), ());
handle.send_cmd(()).await.unwrap();
let state = handle.get_state();
let listener = handle.state_listen_async(|s| async move { true });
listener.cancel();Implementations§
Source§impl<A: Actor> ActorHandle<A>
impl<A: Actor> ActorHandle<A>
Sourcepub fn state_listen_async<F, Fut>(&self, op: F) -> CancelHandle
pub fn state_listen_async<F, Fut>(&self, op: F) -> CancelHandle
异步监听状态变化。
每次状态变化时会调用 op,传入最新状态。
op 返回 true 继续监听,返回 false 停止。
返回的 [ListenerHandle] 被 drop 或调用 cancel() 时停止监听。
Sourcepub fn get_progress(&self) -> A::Progress
pub fn get_progress(&self) -> A::Progress
获取 actor 的最新进度。
pub fn progress_listen_async<F, Fut>(&self, op: F) -> CancelHandle
pub fn get_events_rx(&self) -> Receiver<A::Event>
pub fn events_listen_async<F, Fut>(&self, op: F) -> CancelHandle
pub fn stop(&self)
Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for ActorHandle<A>
impl<A> RefUnwindSafe for ActorHandle<A>where
Sender<<A as Actor>::Cmd>: RefUnwindSafe,
Receiver<<A as Actor>::State>: RefUnwindSafe,
Sender<<A as Actor>::Event>: RefUnwindSafe,
Receiver<<A as Actor>::Progress>: RefUnwindSafe,
impl<A> Send for ActorHandle<A>
impl<A> Sync for ActorHandle<A>
impl<A> Unpin for ActorHandle<A>
impl<A> UnsafeUnpin for ActorHandle<A>where
Sender<<A as Actor>::Cmd>: UnsafeUnpin,
Receiver<<A as Actor>::State>: UnsafeUnpin,
Sender<<A as Actor>::Event>: UnsafeUnpin,
Receiver<<A as Actor>::Progress>: UnsafeUnpin,
impl<A> UnwindSafe for ActorHandle<A>where
Sender<<A as Actor>::Cmd>: UnwindSafe,
Receiver<<A as Actor>::State>: UnwindSafe,
Sender<<A as Actor>::Event>: UnwindSafe,
Receiver<<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