Skip to content

Latest commit

 

History

38 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

leaffall

Lightweight library for staged graceful shutdown.

Crate | Changelog | License

How to use

Add dependency:

leaffall = { version = "<VERSION>", features = ["event"] }

Declare ShutdownRequest static field:

static SHUTDOWN: ShutdownRequest = ShutdownRequest::new();

Check stage for completion:

let complete = SHUTDOWN.is_complete();

SHUTDOWN.wait_complete().await;

Trigger first stage:

SHUTDOWN.trigger();

Guard stage from completion:

let guard = SHUTDOWN.get_guard();

SHUTDOWN.trigger(); // Defer trigger until all guards dropped.

drop(guard); // SHUTDOWN will be triggered here.

Guard futures:

let future = tokio::time::sleep(Duration::from_secs(5));

let guarded_future = SHUTDOWN.guard_future(future);

tokio::spawn(guarded_future); // Don't forget to spawn.

Chain stages:

Note that stages chained in reverse order.

// First stage. Trigger this.
static SHUTDOWN_REQUEST: ShutdownRequest = SHUTDOWN_SERVER.request();

// After SHUTDOWN_REQUEST, but before SHUTDOWN_DATABASE.
static SHUTDOWN_SERVER: ShutdownStage = SHUTDOWN_DATABASE.chain();

// Last stage.
static SHUTDOWN_DATABASE: ShutdownStage = ShutdownStage::new();

About

Lightweight library for staged graceful shutdown.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages