Skip to main content

rust_elm/runtime/
config.rs

1/// Configuration for [`super::engine::Runtime::from_program`] / [`super::engine::Runtime::from_reducer_program`].
2#[derive(Debug, Clone, PartialEq, Eq)]
3pub struct RuntimeConfig {
4    /// Bounded capacity of the action bus (`send_blocking` back-pressures when full).
5    pub bus_capacity: usize,
6    /// Tokio runtime worker threads (async effects / subscriptions).
7    pub worker_threads: usize,
8    /// Name of the dedicated reducer thread.
9    pub thread_name: &'static str,
10}
11
12impl Default for RuntimeConfig {
13    fn default() -> Self {
14        Self {
15            bus_capacity: 4_096,
16            worker_threads: std::thread::available_parallelism()
17                .map(|n| n.get())
18                .unwrap_or(1),
19            thread_name: "rust-elm",
20        }
21    }
22}
23
24impl RuntimeConfig {
25    /// `bus_capacity` only; other fields from [`Default`].
26    pub fn new(bus_capacity: usize) -> Self {
27        Self {
28            bus_capacity,
29            ..Self::default()
30        }
31    }
32}