[][src]Trait lark_actor::Actor

pub trait Actor {
    type InMessage: Send + Sync + 'static;
    fn receive_messages(&mut self, messages: &mut VecDeque<Self::InMessage>);
}

An actor in the task system. This gives a uniform way to create, control, message, and shutdown concurrent workers.

Associated Types

type InMessage: Send + Sync + 'static

Loading content...

Required methods

fn receive_messages(&mut self, messages: &mut VecDeque<Self::InMessage>)

Invoked when new message(s) arrive. Contains all the messages that can be pulled at this time. The actor is free to process as many as they like. So long as messages remain in the dequeue, we'll just keep calling back (possibly appending more messages to the back). Once the queue is empty, we'll block until we can fetch more.

The intended workflow is as follows:

  • If desired, inspect messages and prune messages that become outdated due to later messages in the queue.
  • Invoke messages.pop_front().unwrap() and process that message, then return.
    • In particular, it is probably better to return than to eagerly process all messages in the queue, as it gives the actor a chance to add more messages if they have arrived in the meantime.
      • This is only important if you are trying to remove outdated messages.
Loading content...

Implementors

Loading content...