zestors/runtime/
mod.rs

1/*!
2# Overview
3
4This module currently just exposes two functions:
5- [`set_default_shutdown_time`] and [`get_default_shutdown_time`].
6
7As supervision and distribution get implemented this module will fill further.
8
9| __<--__ [`handler`](crate::handler) | [`supervision`](crate::supervision) __-->__ |
10|---|---|
11*/
12#[allow(unused)]
13use crate::all::*;
14
15use std::{
16    sync::atomic::{AtomicU32, AtomicU64, Ordering},
17    time::Duration,
18};
19
20static DEFAULT_SHUTDOWN_TIME_NANOS: AtomicU32 = AtomicU32::new(0);
21static DEFAULT_SHUTDOWN_TIME_SECS: AtomicU64 = AtomicU64::new(1);
22
23/// Set the default shutdown time-limit.
24/// 
25/// This limit is the limit applied to a default [`Link`], and changes how long these processes
26/// have to exit before 
27pub fn set_default_shutdown_time(duration: Duration) {
28    DEFAULT_SHUTDOWN_TIME_NANOS.store(duration.subsec_nanos(), Ordering::Release);
29    DEFAULT_SHUTDOWN_TIME_SECS.store(duration.as_secs(), Ordering::Release);
30}
31
32/// Get the default shutdown time-limit.
33pub fn get_default_shutdown_time() -> Duration {
34    Duration::new(
35        DEFAULT_SHUTDOWN_TIME_SECS.load(Ordering::Acquire),
36        DEFAULT_SHUTDOWN_TIME_NANOS.load(Ordering::Acquire),
37    )
38}
39
40#[cfg(test)]
41mod test {
42    use super::*;
43    #[test]
44    fn default_shutdown_time() {
45        assert_eq!(get_default_shutdown_time(), Duration::from_secs(1));
46        set_default_shutdown_time(Duration::from_secs(2));
47        assert_eq!(get_default_shutdown_time(), Duration::from_secs(2));
48    }
49}