Trait fluxion::actor::Actor

source ·
pub trait Actor<C: FluxionParams>: Send + Sync + 'static {
    type Error: Debug + PartialEq + Send + Sync + 'static;

    // Provided methods
    fn initialize<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _context: &'life1 ActorContext<C>
    ) -> Pin<Box<dyn Future<Output = Result<(), ActorError<Self::Error>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn deinitialize<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _context: &'life1 ActorContext<C>
    ) -> Pin<Box<dyn Future<Output = Result<(), ActorError<Self::Error>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn cleanup<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        _context: &'life1 ActorContext<C>,
        _error: Option<&'life2 ActorError<Self::Error>>
    ) -> Pin<Box<dyn Future<Output = Result<(), ActorError<Self::Error>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Actor

This trait must be implemented for all Actors. It contains three functions, Actor::initialize, Actor::deinitialize, and Actor::cleanup. Each have a default implementation which does nothing.

Associated Types

The Actor trait takesan associated type Error, which is the custom error type returned by the actor.

Generics

The single generic taken by Actor is configuration data used by Fluxion for compile time config. It is a type implementing the trait crate::types::params::FluxionParams, where each associated type is configurable. This mainly contains information such as what the notification type used by the system is, which async executor is being used, and other related information. Implementors of Actor may wish to confine themselves to specific parameters (such as a specific executor), and as such this is provided as a generic instead of an associated type.

Initialization

When an Actor is added to a system, a separate management, or “supervisor” task is started which oversees the Actor’s lifetime. When this supervisor task is started, Actor::initialize is immediately called. If successful, the supervisor begins the Actor’s main loop. Upon failure, the supervisor immediately skips to the cleanup phase.

Deinitialization

If the actor’s main loop exits, either gracefully or by an error, Actor::deinitialize is called. Reguardless of if this function fails or not, the actor skips to the cleanup phase.

Cleanup

After the supervisor task exits, Actor::cleanup is called. In place of the ActorContext, an Option<Self::Error> is provided, containing None if the supervisor exited gracefully, or Some(error) if the supervisor task failed with an error. This function is always called on actor exit. If Actor::cleanup returns an error, the error is simply logged if tracing is enabled, and the actor stops.

Async

This trait uses async_trait when on stable. Once async functions in traits are stablized, this dependency will be removed. On nightly, the nightly feature may be enabled, which uses #![feature(async_fn_in_trait)]

Required Associated Types§

source

type Error: Debug + PartialEq + Send + Sync + 'static

The error type returned by the actor

Provided Methods§

source

fn initialize<'life0, 'life1, 'async_trait>( &'life0 mut self, _context: &'life1 ActorContext<C> ) -> Pin<Box<dyn Future<Output = Result<(), ActorError<Self::Error>>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The function run upon actor initialization

source

fn deinitialize<'life0, 'life1, 'async_trait>( &'life0 mut self, _context: &'life1 ActorContext<C> ) -> Pin<Box<dyn Future<Output = Result<(), ActorError<Self::Error>>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The function run upon actor deinitialization

source

fn cleanup<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _context: &'life1 ActorContext<C>, _error: Option<&'life2 ActorError<Self::Error>> ) -> Pin<Box<dyn Future<Output = Result<(), ActorError<Self::Error>>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

The function run upon actor cleanup

Object Safety§

This trait is not object safe.

Implementors§