columbo 0.2.3

Async SSR streaming suspense — render placeholders, stream HTML replacements as futures resolve.
Documentation
use tokio_util::sync::CancellationToken;

/// A wrapper around [`CancellationToken`] that calls `cancel()` when dropped.
pub(crate) struct CancelOnDrop {
  inner: CancellationToken,
}

impl CancelOnDrop {
  pub(crate) fn new(inner: CancellationToken) -> Self { CancelOnDrop { inner } }
}

impl Drop for CancelOnDrop {
  fn drop(&mut self) {
    tracing::debug!(
      "response stream dropped; indicating cancellation to listening futures"
    );
    self.inner.cancel()
  }
}