Skip to main content

GuardSignals

Struct GuardSignals 

Source
pub struct GuardSignals { /* private fields */ }
Expand description

Signal controller for guard-style tick loops.

Sets up SIGINT/SIGTERM handling with double-tap support and exposes a should_stop() flag that the loop checks between ticks.

Dropping GuardSignals stops the listener thread and joins it.

§Example

use std::time::Duration;
use sysprims_core::guard_signals::GuardSignals;
use sysprims_core::time::Tick;

let signals = GuardSignals::start().unwrap();
let mut tick = Tick::new(Duration::from_secs(5)).unwrap();
while !signals.should_stop() {
    // do guard work …
    tick.sleep_until_next();
}

Implementations§

Source§

impl GuardSignals

Source

pub fn start() -> SysprimsResult<Self>

Set up signal handlers and start the listener thread.

Registers SIGINT and SIGTERM handlers that set the stop flag, enables double-tap (catalog defaults), and spawns a background thread running SignalManager::listen().

If the listener exits early (error or unexpected return), the stop flag is set so the guard loop does not run without signal responsiveness.

Source

pub fn should_stop(&self) -> bool

Check whether a shutdown signal has been received.

Source

pub fn request_stop(&self)

Request stop (useful for programmatic shutdown, e.g. max-iterations).

Source

pub fn manager(&self) -> &SignalManager

Access the underlying SignalManager (for shutdown hooks or test injection).

Source

pub fn stop_flag_handle(&self) -> StopFlagHandle

Get a write handle to the shared stop flag.

Used by GuardStopHandle to request stop from another thread without holding a reference to GuardSignals.

Trait Implementations§

Source§

impl Drop for GuardSignals

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.