Skip to main content

aion/runtime/
config.rs

1//! Builder-supplied scheduler configuration for the embedded runtime.
2
3use std::time::Duration;
4
5/// Configuration used when constructing the embedded BEAM runtime.
6#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
7pub struct RuntimeConfig {
8    /// Optional scheduler thread count supplied by the engine builder.
9    ///
10    /// `None` is passed through to beamr so the embedded runtime applies its own
11    /// runtime-aware default.
12    pub thread_count: Option<usize>,
13
14    /// Bounded readiness and retry policy for live signal mailbox delivery.
15    pub signal_delivery: SignalDeliveryConfig,
16
17    /// Whether the durable-outbox fan-out dispatch path is enabled.
18    pub outbox_enabled: bool,
19}
20
21/// Bounded signal delivery retry policy supplied by engine configuration.
22#[derive(Clone, Copy, Debug, Eq, PartialEq)]
23pub struct SignalDeliveryConfig {
24    /// Maximum time to wait for a just-spawned process body to materialize.
25    pub ready_timeout: Duration,
26
27    /// Maximum number of mailbox enqueue attempts after the ready gate.
28    pub max_enqueue_attempts: u32,
29
30    /// Initial sleep between failed enqueue attempts.
31    pub initial_backoff: Duration,
32
33    /// Upper bound for exponential backoff between enqueue attempts.
34    pub max_backoff: Duration,
35}
36
37impl Default for SignalDeliveryConfig {
38    fn default() -> Self {
39        Self::new(
40            Duration::from_millis(50),
41            8,
42            Duration::from_millis(1),
43            Duration::from_millis(8),
44        )
45    }
46}
47
48impl SignalDeliveryConfig {
49    /// Create an explicit signal delivery policy.
50    #[must_use]
51    pub const fn new(
52        ready_timeout: Duration,
53        max_enqueue_attempts: u32,
54        initial_backoff: Duration,
55        max_backoff: Duration,
56    ) -> Self {
57        Self {
58            ready_timeout,
59            max_enqueue_attempts,
60            initial_backoff,
61            max_backoff,
62        }
63    }
64}
65
66impl RuntimeConfig {
67    /// Create runtime configuration from the builder-supplied scheduler count.
68    #[must_use]
69    pub fn new(thread_count: Option<usize>) -> Self {
70        Self {
71            thread_count,
72            signal_delivery: SignalDeliveryConfig::default(),
73            outbox_enabled: false,
74        }
75    }
76
77    /// Override the signal delivery retry policy.
78    #[must_use]
79    pub const fn with_signal_delivery(mut self, signal_delivery: SignalDeliveryConfig) -> Self {
80        self.signal_delivery = signal_delivery;
81        self
82    }
83
84    /// Override whether the durable-outbox fan-out dispatch path is enabled.
85    #[must_use]
86    pub const fn with_outbox_enabled(mut self, enabled: bool) -> Self {
87        self.outbox_enabled = enabled;
88        self
89    }
90}