Impl new convenient fn AutoAbortJoinHandle::spawn

As a shortcut to `AutoAbortJoinHandle::new(tokio::spawn(...))`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-08-04 18:30:48 +10:00
parent 64e948f941
commit 2103dea3ac
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -16,6 +16,18 @@ impl<T> AutoAbortJoinHandle<T> {
}
}
impl<T> AutoAbortJoinHandle<T>
where
T: Send + 'static,
{
pub fn spawn<F>(future: F) -> Self
where
F: Future<Output = T> + Send + 'static,
{
Self(tokio::spawn(future))
}
}
impl<T> Drop for AutoAbortJoinHandle<T> {
fn drop(&mut self) {
self.0.abort();