SupervisionRef

Struct SupervisionRef 

Source
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: H

Implementations§

Source§

impl<M: Send + 'static, H: ActoHandle> SupervisionRef<M, H>

Source

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
}
Source

pub fn map_handle<S, F>( self, f: F, ) -> SupervisionRef<M, MappedActoHandle<H, F, S>>
where F: FnOnce(H::Output) -> S + Send + Sync + Unpin + 'static, S: Send + 'static,

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more