soft-cycle
A small async Rust crate for coordinating soft restarts and graceful shutdowns using a shared controller. Tasks can wait on a listener and react when a restart or shutdown is triggered.
Usage
Use [SoftCycleController::new] to create a new controller instance. Use try_restart and try_shutdown to trigger a restart or shutdown respectively. Only the first call to either method will succeed until the controller is cleared via clear. Use the listener method to be notified when a restart or shutdown is triggered.
Notice
If listener is called while the controller is already in a triggered state, it will resolve on the next trigger, not the current one.
Currently, shutdowns and restarts are only distinguishable by the boolean returned by the listener: true for shutdown, false for restart. They have no other differing behavior.
Features
global_instance(default): Enables a process-wide default controller and the free functions [get_lifetime_controller], [try_restart], [try_shutdown], [listener], and [clear] at the crate root.
Example
use Arc;
use SoftCycleController;
use ;
async