Skip to main content

ActorHandler

Trait ActorHandler 

Source
pub trait ActorHandler: Send + Sync {
    // Required methods
    fn on_message<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ctx: &'life1 mut dyn ActorContext,
        message: &'life2 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, ActorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn on_alarm<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 mut dyn ActorContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

The protocol for one kind of actor. A module implements it and registers it with HarnessBuilder::actor; the host owns the serialization and calls these.

Implementations must be stateless — all state lives in the actor and is reached through ActorContext — so a host that drops the handler between events (a hibernating Durable Object) can reconstruct it.

Required Methods§

Source

fn on_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 mut dyn ActorContext, message: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, ActorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

A message arrived. Writes staged on ctx commit only if this returns Ok with a reply within MAX_ACTOR_REPLY_BYTES.

Source

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

The alarm fired. Writes staged on ctx commit only if this returns Ok; a handler that does not re-arm leaves no alarm set.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§