#![forbid(unsafe_code)]
#![deny(missing_docs)]
use tokio_util::sync::CancellationToken;
#[derive(Debug, Clone)]
pub struct CancellationScope {
inner: CancellationToken,
}
impl CancellationScope {
#[must_use]
pub fn new() -> Self {
Self {
inner: CancellationToken::new(),
}
}
#[must_use]
pub fn child(&self) -> Self {
Self {
inner: self.inner.child_token(),
}
}
pub fn cancel(&self) {
self.inner.cancel();
}
#[must_use]
pub fn is_cancelled(&self) -> bool {
self.inner.is_cancelled()
}
pub async fn cancelled(&self) {
self.inner.cancelled().await;
}
}
impl Default for CancellationScope {
fn default() -> Self {
Self::new()
}
}