[−][src]Trait acteur::Receive
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 Assistant.
use async_trait::async_trait; use acteur::{Assistant, Receive, Acteur}; #[derive(Debug)] struct SalaryChanged(u32); #[async_trait] impl Receive<SalaryChanged> for Employee { async fn handle(&mut self, message: SalaryChanged, _: &Assistant<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]fn handle<'life0, 'life1, 'async_trait>(
&'life0 mut self,
message: M,
assistant: &'life1 Assistant<Self>
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
&'life0 mut self,
message: M,
assistant: &'life1 Assistant<Self>
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,