agner_actors/
system_config.rs

1use std::sync::Arc;
2use std::time::Duration;
3
4use crate::exit_handler::{ExitHandler, NoopExitHandler};
5
6/// Configuration for [`System`](crate::system::System)
7#[derive(Debug, Clone)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct SystemConfig {
10    /// max number of actors in the [`System`](crate::system::System)
11    pub max_actors: usize,
12
13    /// max duration given for an actor to gracefully terminate
14    pub actor_termination_timeout: Duration,
15
16    /// exit handler
17    #[cfg_attr(feature = "serde", serde(skip, default = "defaults::default_exit_handler"))]
18    pub exit_handler: Arc<dyn ExitHandler>,
19}
20
21impl Default for SystemConfig {
22    fn default() -> Self {
23        Self {
24            max_actors: defaults::DEFAULT_MAX_ACTORS,
25            actor_termination_timeout: defaults::DEFAULT_ACTOR_TERMINATION_TIMEOUT,
26            exit_handler: defaults::default_exit_handler(),
27        }
28    }
29}
30
31mod defaults {
32    use super::*;
33
34    pub(super) const DEFAULT_MAX_ACTORS: usize = 1_024;
35    pub(super) const DEFAULT_ACTOR_TERMINATION_TIMEOUT: Duration = Duration::from_secs(30);
36
37    pub(super) fn default_exit_handler() -> Arc<dyn ExitHandler> {
38        Arc::new(NoopExitHandler)
39    }
40}