Split async-std support and refactor

This commit is contained in:
Michael Pfaff 2022-06-15 16:47:49 -04:00
parent cb7b6446de
commit ba59933810
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
3 changed files with 37 additions and 32 deletions

View File

@ -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" ]

View File

@ -1,3 +1,5 @@
#[cfg(feature = "async-std-task")]
mod impl_task {
use async_std::task::JoinHandle;
use crate::{DropGuard, DropGuarded};
@ -20,3 +22,4 @@ impl<T> core::future::Future for DropGuard<JoinHandle<T>> {
core::pin::Pin::new(handle).poll(cx)
}
}
}

View File

@ -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")]
mod impl_sync {
use crate::DropGuarded;
impl DropGuarded for tokio1::sync::oneshot::Sender<()> {
#[inline]
fn cancel(self) {
let _ = self.send(());
}
}
#[cfg(all(feature = "tokio1-sync", feature = "std"))]
#[cfg(feature = "std")]
impl DropGuarded for std::sync::Arc<tokio1::sync::Semaphore> {
#[inline]
fn cancel(self) {
self.close();
}
}
}