Split async-std support and refactor
This commit is contained in:
parent
cb7b6446de
commit
ba59933810
|
@ -12,7 +12,8 @@ arbitrary = [ ]
|
|||
|
||||
std = [ ]
|
||||
|
||||
async-std = [ "dep:async-std", "async-std/alloc", "async-std/default" ]
|
||||
async-std = [ "dep:async-std" ]
|
||||
async-std-task = [ "async-std", "async-std/alloc", "async-std/default" ]
|
||||
tokio1 = [ "dep:tokio1" ]
|
||||
tokio1-sync = [ "tokio1", "tokio1/sync" ]
|
||||
tokio1-task = [ "tokio1", "tokio1/rt" ]
|
||||
|
|
|
@ -1,22 +1,25 @@
|
|||
use async_std::task::JoinHandle;
|
||||
#[cfg(feature = "async-std-task")]
|
||||
mod impl_task {
|
||||
use async_std::task::JoinHandle;
|
||||
|
||||
use crate::{DropGuard, DropGuarded};
|
||||
use crate::{DropGuard, DropGuarded};
|
||||
|
||||
impl<T> DropGuarded for JoinHandle<T> {
|
||||
#[inline]
|
||||
fn cancel(self) {
|
||||
let _ = JoinHandle::<T>::cancel(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> core::future::Future for DropGuard<JoinHandle<T>> {
|
||||
type Output = T;
|
||||
|
||||
fn poll(
|
||||
mut self: core::pin::Pin<&mut Self>,
|
||||
cx: &mut core::task::Context<'_>,
|
||||
) -> core::task::Poll<Self::Output> {
|
||||
let handle = (*self).inner.as_mut().expect("can only be None in drop");
|
||||
core::pin::Pin::new(handle).poll(cx)
|
||||
impl<T> DropGuarded for JoinHandle<T> {
|
||||
#[inline]
|
||||
fn cancel(self) {
|
||||
let _ = JoinHandle::<T>::cancel(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> core::future::Future for DropGuard<JoinHandle<T>> {
|
||||
type Output = T;
|
||||
|
||||
fn poll(
|
||||
mut self: core::pin::Pin<&mut Self>,
|
||||
cx: &mut core::task::Context<'_>,
|
||||
) -> core::task::Poll<Self::Output> {
|
||||
let handle = (*self).inner.as_mut().expect("can only be None in drop");
|
||||
core::pin::Pin::new(handle).poll(cx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use crate::DropGuarded;
|
||||
|
||||
#[cfg(feature = "tokio1-task")]
|
||||
mod impl_task {
|
||||
use crate::{DropGuard, DropGuarded};
|
||||
|
@ -28,17 +26,20 @@ mod impl_task {
|
|||
}
|
||||
|
||||
#[cfg(feature = "tokio1-sync")]
|
||||
impl DropGuarded for tokio1::sync::oneshot::Sender<()> {
|
||||
#[inline]
|
||||
fn cancel(self) {
|
||||
let _ = self.send(());
|
||||
}
|
||||
}
|
||||
mod impl_sync {
|
||||
use crate::DropGuarded;
|
||||
|
||||
#[cfg(all(feature = "tokio1-sync", feature = "std"))]
|
||||
impl DropGuarded for std::sync::Arc<tokio1::sync::Semaphore> {
|
||||
#[inline]
|
||||
fn cancel(self) {
|
||||
self.close();
|
||||
impl DropGuarded for tokio1::sync::oneshot::Sender<()> {
|
||||
#[inline]
|
||||
fn cancel(self) {
|
||||
let _ = self.send(());
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "std")]
|
||||
impl DropGuarded for std::sync::Arc<tokio1::sync::Semaphore> {
|
||||
#[inline]
|
||||
fn cancel(self) {
|
||||
self.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue