Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tokio-util/src/task/abort_on_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ impl<T> AbortOnDropHandle<T> {
Self(handle)
}

/// Shortcut for [`tokio::spawn`] followed by [`Self::new`].
///
/// # Examples
///
/// ```
/// # use tokio_util::task::AbortOnDropHandle;
/// # #[tokio::main]
/// # async fn main() {
/// let _handle = AbortOnDropHandle::spawn(async move {
/// // ...
/// });
/// # }
/// ```
#[track_caller]
pub fn spawn<F>(future: F) -> Self
where
F: Future<Output = T> + Send + 'static,
F::Output: Send + 'static,
{
Self::new(tokio::spawn(future))
}

/// Abort the task associated with this handle,
/// equivalent to [`JoinHandle::abort`].
pub fn abort(&self) {
Expand Down
Loading