6 releases
Uses new Rust 2024
| new 0.3.10 | Jan 27, 2026 |
|---|---|
| 0.3.9 | Jan 25, 2026 |
#760 in Asynchronous
18KB
323 lines
Sigterm
Signal-aware async control and cancellation primitives for Tokio.
sigterm abstracts away the boilerplate of listening for system signals (Ctrl+C, SIGTERM, etc.) and coordinating shutdown across multiple asynchronous tasks.
Features
- Signal Waiting: Wait for
Ctrl+CorSIGTERMacross platforms with a singleawait. Usetry_wait()for non-panicking version. - Cancellation Tokens: Hierarchy-based cancellation (parent cancels child) powered by
tokio-util. - Shutdown Primitives:
Shutdown: One-shot channel for single-task termination.Broadcast: Notify multiple subscribers of a shutdown event.ShutdownGuard: RAII guard that triggers shutdown when dropped (useful for panics).
- Framework Integration:
shutdown_signal()helper designed for seamless integration withaxum::serve. - Unix Extensions: Listen for custom signal sets (
SIGHUP,SIGQUIT, etc.) on Unix systems.
Usage Examples
Check the examples directory for runnable code:
- Basic Usage:
examples/simple.rs- Wait for a simple shutdown signal. - Server Integration:
examples/shutdown_signal.rs- Combine system signals with internal cancellation (e.g., for Axum). - Task Orchestration:
examples/broadcast.rs- Coordinate multiple workers. - Hierarchical Cancellation:
examples/cancellation.rs- Manage tree-structured tasks. - Scope Guard:
examples/guard.rs- Ensure shutdown on exit or panic.
Installation
[dependencies]
sigterm = { version = "0.3", features = ["full"] }
License
Released under the MIT License © 2026 Canmi
Dependencies
~0–2.7MB
~47K SLoC