pub trait WaitForTerminationTrait {
// Required methods
fn get_warn_lock_mut(&mut self) -> &mut bool;
fn get_error_lock_mut(&mut self) -> &mut bool;
// Provided method
fn wait_for_termination(
&mut self,
rx_waiting_thread_from_signal_handler: &mut AquaReceiver<InternalCommand>,
sleep_duration: Duration,
origin: &str,
) { ... }
}Expand description
Defines a standard behavior for components that need to wait for a termination signal.
This trait is implemented by long-running components (often those running in their own thread)
that need to perform a graceful shutdown. After completing their primary tasks, they can call
wait_for_termination to pause execution efficiently until the central signal handler
sends a final InternalCommand::Terminate command.
Required Methods§
Sourcefn get_warn_lock_mut(&mut self) -> &mut bool
fn get_warn_lock_mut(&mut self) -> &mut bool
Provides a mutable reference to the component’s warning lock flag. This flag is used to prevent log-flooding with inapplicable command warnings.
Sourcefn get_error_lock_mut(&mut self) -> &mut bool
fn get_error_lock_mut(&mut self) -> &mut bool
Provides a mutable reference to the component’s error lock flag. This flag is used to prevent log-flooding with the channel receive errors.
Provided Methods§
Sourcefn wait_for_termination(
&mut self,
rx_waiting_thread_from_signal_handler: &mut AquaReceiver<InternalCommand>,
sleep_duration: Duration,
origin: &str,
)
fn wait_for_termination( &mut self, rx_waiting_thread_from_signal_handler: &mut AquaReceiver<InternalCommand>, sleep_duration: Duration, origin: &str, )
Implements the graceful shutdown wait loop for several threads (default implementation).
This function enters a loop that continuously checks for a termination command from the
signal handler. It uses try_recv for non-blocking message checking.
- If
InternalCommand::Terminateis received, the loop exits. - If any other
InternalCommandis received, a warning is logged. A lock flag (lock_warn_inapplicable_command_signal_handler) prevents spamming the log with repeated warnings. - If the channel receive operation fails (e.g., the sender is dropped), an error is
logged. A lock flag (
lock_error_channel_receive_termination) prevents repeated error logs.
The thread sleeps for the specified sleep_duration between each check
to minimize CPU consumption.
§Arguments
rx_waiting_thread_from_signal_handler- The channel receiver to listen for commands.sleep_duration- The duration to pause between checks.origin- module name which called this function.