[][src]Trait acteur::Receive

pub trait Receive<M: Debug> where
    Self: Sized + Actor
{ #[must_use] pub fn handle<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        message: M,
        assistant: &'life1 ActorAssistant<Self>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; }

This Trait allow Actors to receive messages. This is the most efficient way to process messages as it doesn't require to respond the message.

If you want to respond to messages, use the Respond trait.

This trait is compatible with Respond trait as you can implement, for the same message, both traits. This trait will be executed when using the "send_to_actor" or "send_to_actor_sync" method from System or the "send_to_actor" method from ActorAssistant.

use async_trait::async_trait;
use acteur::{ActorAssistant, Receive, Acteur};

#[derive(Debug)]
struct SalaryChanged(u32);

#[async_trait]
impl Receive<SalaryChanged> for Employee {
    async fn handle(&mut self, message: SalaryChanged, _: &ActorAssistant<Employee>) {
        self.salary = message.0;
    }
}

fn main() {
    let sys = Acteur::new();

    sys.send_to_actor_sync::<Employee, SalaryChanged>(42, SalaryChanged(55000));

    sys.wait_until_stopped();
}

Required methods

#[must_use]pub fn handle<'life0, 'life1, 'async_trait>(
    &'life0 mut self,
    message: M,
    assistant: &'life1 ActorAssistant<Self>
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait,
    Self: 'async_trait, 
[src]

This method is called each time a message is received. You can use the ActorAssistant to send messages from actors, System to send messages from services and Acteur to send messages from outside the framework

Loading content...

Implementors

Loading content...