Use tokio_util::CancellationToken everywhere
This commit is contained in:
parent
53868ad45e
commit
bed7433d8e
16 changed files with 176 additions and 178 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use anyhow::bail;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tracing::{error, trace, Instrument};
|
||||
|
||||
/// Spawns a future with tracing instrumentation.
|
||||
|
|
@ -32,3 +34,18 @@ pub fn spawn(
|
|||
.instrument(span);
|
||||
tokio::task::spawn(fut)
|
||||
}
|
||||
|
||||
pub fn spawn_with_cancel(
|
||||
span: tracing::Span,
|
||||
cancellation_token: CancellationToken,
|
||||
fut: impl std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
|
||||
) -> tokio::task::JoinHandle<()> {
|
||||
spawn(span, async move {
|
||||
tokio::select! {
|
||||
_ = cancellation_token.cancelled() => {
|
||||
bail!("cancelled");
|
||||
},
|
||||
r = fut => r
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue