Trait acto::ActoRuntime

source ·
pub trait ActoRuntime: Clone + Send + Sync + 'static {
    type ActoHandle<O: Send + 'static>: ActoHandle<Output = O>;
    type Sender<M: Send + 'static>: Sender<M>;
    type Receiver<M: Send + 'static>: Receiver<M>;

    // Required methods
    fn name(&self) -> &str;
    fn mailbox<M: Send + 'static>(&self) -> (Self::Sender<M>, Self::Receiver<M>);
    fn spawn_task<T>(
        &self,
        id: ActoId,
        name: SmolStr,
        task: T
    ) -> Self::ActoHandle<T::Output>
       where T: Future + Send + 'static,
             T::Output: Send + 'static;

    // Provided method
    fn spawn_actor<M, F, Fut, S>(
        &self,
        name: &str,
        actor: F
    ) -> SupervisionRef<M, Self::ActoHandle<Fut::Output>>
       where M: Send + 'static,
             F: FnOnce(ActoCell<M, Self, S>) -> Fut,
             Fut: Future + Send + 'static,
             Fut::Output: Send + 'static,
             S: Send + 'static { ... }
}
Expand description

For implementors: the interface of a runtime for operating actors.

Cloning a runtime should be cheap, it SHOULD be using the Arc<Inner> pattern.

Required Associated Types§

source

type ActoHandle<O: Send + 'static>: ActoHandle<Output = O>

The type of handle used for joining the actor’s task.

source

type Sender<M: Send + 'static>: Sender<M>

The type of sender for emitting messages towards the actor.

source

type Receiver<M: Send + 'static>: Receiver<M>

The type of receiver for obtaining messages sent towards the actor.

Required Methods§

source

fn name(&self) -> &str

A name for this runtime, used mainly in logging.

source

fn mailbox<M: Send + 'static>(&self) -> (Self::Sender<M>, Self::Receiver<M>)

Create a new pair of sender and receiver for a fresh actor.

source

fn spawn_task<T>( &self, id: ActoId, name: SmolStr, task: T ) -> Self::ActoHandle<T::Output>
where T: Future + Send + 'static, T::Output: Send + 'static,

Spawn an actor’s task to be driven independently and return an ActoHandle to abort or join it.

Provided Methods§

source

fn spawn_actor<M, F, Fut, S>( &self, name: &str, actor: F ) -> SupervisionRef<M, Self::ActoHandle<Fut::Output>>
where M: Send + 'static, F: FnOnce(ActoCell<M, Self, S>) -> Fut, Fut: Future + Send + 'static, Fut::Output: Send + 'static, S: Send + 'static,

Provided function for spawning actors.

Uses the above utilities and cannot be implemented by downstream crates.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl ActoRuntime for AcTokioRuntime

Available on crate feature tokio only.
§

type ActoHandle<O: Send + 'static> = TokioJoinHandle<O>

§

type Sender<M: Send + 'static> = TokioSender<M>

§

type Receiver<M: Send + 'static> = TokioReceiver<M>