Skip to main content

atomr_core/dispatch/
mailbox.rs

1//! Mailbox configuration. akka.net: `Dispatch/Mailbox.cs`, `Mailboxes.cs`.
2//!
3//! The mailbox holds queued messages for a single actor. Our implementation
4//! uses `tokio::mpsc::UnboundedReceiver` as the user queue and a separate
5//! unbounded queue for system messages; `ActorCell` polls with system priority.
6
7use std::time::Duration;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
10pub enum MailboxKind {
11    #[default]
12    Unbounded,
13    Bounded,
14    UnboundedDeque,
15    UnboundedPriority,
16    UnboundedStablePriority,
17}
18
19#[derive(Debug, Clone)]
20pub struct MailboxConfig {
21    pub kind: MailboxKind,
22    pub capacity: usize,
23    pub push_timeout: Duration,
24}
25
26impl Default for MailboxConfig {
27    fn default() -> Self {
28        Self { kind: MailboxKind::Unbounded, capacity: 1_000, push_timeout: Duration::from_secs(10) }
29    }
30}
31
32/// Marker type exposed publicly — the concrete storage lives inside
33/// `ActorCell` (tokio mpsc channels and an auxiliary priority heap when needed).
34#[derive(Debug, Clone, Default)]
35pub struct Mailbox {
36    pub config: MailboxConfig,
37}
38
39impl Mailbox {
40    pub fn new(config: MailboxConfig) -> Self {
41        Self { config }
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn default_mailbox_kind_unbounded() {
51        assert_eq!(Mailbox::default().config.kind, MailboxKind::Unbounded);
52    }
53}