pub struct SupervisionRef<M, H> {
pub me: ActoRef<M>,
pub handle: H,
}Expand description
A package of an actor’s ActoRef and ActoHandle.
This is the result of [ActoCell::spawn] and can be passed to [ActoCell::supervise].
Fields§
§me: ActoRef<M>§handle: HImplementations§
Source§impl<M: Send + 'static, H: ActoHandle> SupervisionRef<M, H>
impl<M: Send + 'static, H: ActoHandle> SupervisionRef<M, H>
Sourcepub fn contramap<M2: Send + 'static>(
self,
f: impl Fn(M2) -> M + Send + Sync + 'static,
) -> SupervisionRef<M2, H>
pub fn contramap<M2: Send + 'static>( self, f: impl Fn(M2) -> M + Send + Sync + 'static, ) -> SupervisionRef<M2, H>
Derive a new reference by embedding the supervisor-required type M2 into the message schema.
struct Shutdown;
enum ActorCommand {
Shutdown(Shutdown),
DoStuff(String),
}
async fn top_level(mut cell: ActoCell<(), impl ActoRuntime>) {
let supervisor = cell.spawn_supervised("super",
|mut cell: ActoCell<SupervisionRef<Shutdown, _>, _>| async move {
while let ActoInput::Message(actor) = cell.recv().await {
let actor_ref = cell.supervise(actor);
// use reference to shut it down at a later time
}
// if any of them fail, shut all of them down
}
);
let actor = cell.spawn("actor", |mut cell: ActoCell<_, _>| async move {
while let ActoInput::Message(msg) = cell.recv().await {
if let ActorCommand::Shutdown(_) = msg {
break;
}
}
});
let actor_ref = actor.me.clone();
supervisor.send(actor.contramap(ActorCommand::Shutdown));
// do stuff with actor_ref
}Sourcepub fn map_handle<S, F>(
self,
f: F,
) -> SupervisionRef<M, MappedActoHandle<H, F, S>>
pub fn map_handle<S, F>( self, f: F, ) -> SupervisionRef<M, MappedActoHandle<H, F, S>>
Map the return type of the contained ActoHandle to match the intended supervisor.
async fn top_level(mut cell: ActoCell<(), impl ActoRuntime, String>) -> ActoInput<(), String> {
let actor = cell.spawn("actor", |mut cell: ActoCell<(), _>| async move {
// some async computation that leads to the result
42
});
// cannot supervise without transforming result to a String
let ar = cell.supervise(actor.map_handle(|number| number.to_string()));
// now do something with the actor reference
}Auto Trait Implementations§
impl<M, H> Freeze for SupervisionRef<M, H>where
H: Freeze,
impl<M, H> !RefUnwindSafe for SupervisionRef<M, H>
impl<M, H> Send for SupervisionRef<M, H>where
H: Send,
impl<M, H> Sync for SupervisionRef<M, H>where
H: Sync,
impl<M, H> Unpin for SupervisionRef<M, H>where
H: Unpin,
impl<M, H> !UnwindSafe for SupervisionRef<M, H>
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