We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 925c614 commit bec2347Copy full SHA for bec2347
tokio-util/src/task/abort_on_drop.rs
@@ -30,6 +30,28 @@ impl<T> AbortOnDropHandle<T> {
30
Self(handle)
31
}
32
33
+ /// Shortcut for [`tokio::spawn`] followed by [`Self::new`].
34
+ ///
35
+ /// # Examples
36
37
+ /// ```
38
+ /// # use tokio_util::task::AbortOnDropHandle;
39
+ /// # #[tokio::main]
40
+ /// # async fn main() {
41
+ /// let _handle = AbortOnDropHandle::spawn(async move {
42
+ /// // ...
43
+ /// });
44
+ /// # }
45
46
+ #[track_caller]
47
+ pub fn spawn<F>(future: F) -> Self
48
+ where
49
+ F: Future<Output = T> + Send + 'static,
50
+ F::Output: Send + 'static,
51
+ {
52
+ Self::new(tokio::spawn(future))
53
+ }
54
+
55
/// Abort the task associated with this handle,
56
/// equivalent to [`JoinHandle::abort`].
57
pub fn abort(&self) {
0 commit comments