sigterm 0.3.10

Signal-aware async control and cancellation primitives for Tokio.
Documentation
/* src/cancel.rs */

//! Hierarchy-based cancellation tokens.
//!
//! This module provides [`CancellationToken`], which allows for signaling
//! cancellation to one or more tasks. Tokens can be linked in a parent-child
//! relationship: if a parent token is cancelled, all its children are
//! automatically cancelled.

pub use tokio_util::sync::CancellationToken;

#[cfg(test)]
mod tests {
	use super::*;

	#[tokio::test]
	async fn test_child_cancellation() {
		let parent = CancellationToken::new();
		let child = parent.child_token();

		parent.cancel();
		assert!(child.is_cancelled());
	}

	#[tokio::test]
	async fn test_independent_child_cancellation() {
		let parent = CancellationToken::new();
		let child = parent.child_token();

		child.cancel();
		assert!(child.is_cancelled());
		assert!(!parent.is_cancelled());
	}
}