From 2103dea3acdf755fba0d5497087852b6b3bc3b7f Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 4 Aug 2022 18:30:48 +1000 Subject: [PATCH] Impl new convenient fn `AutoAbortJoinHandle::spawn` As a shortcut to `AutoAbortJoinHandle::new(tokio::spawn(...))` Signed-off-by: Jiahao XU --- src/helpers/auto_abort_join_handle.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/helpers/auto_abort_join_handle.rs b/src/helpers/auto_abort_join_handle.rs index fa476a8b..8faa1f25 100644 --- a/src/helpers/auto_abort_join_handle.rs +++ b/src/helpers/auto_abort_join_handle.rs @@ -16,6 +16,18 @@ impl AutoAbortJoinHandle { } } +impl AutoAbortJoinHandle +where + T: Send + 'static, +{ + pub fn spawn(future: F) -> Self + where + F: Future + Send + 'static, + { + Self(tokio::spawn(future)) + } +} + impl Drop for AutoAbortJoinHandle { fn drop(&mut self) { self.0.abort();