From ff20c5f998a4f2717b0e39fce1db528d8a5258ac Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Sun, 20 Nov 2022 13:36:37 -0500 Subject: [PATCH] build: Feature gate async-std executor --- Cargo.toml | 7 ++++++- src/executor.rs | 2 ++ src/testing_util.rs | 1 + src/util/async_actor.rs | 5 +++-- src/util/sync_actor.rs | 5 +++-- src/util/wrapped_channels.rs | 5 +++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e3a604c..c8eae2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,14 @@ repository = "https://git.sr.ht/~thatonelutenist/peerdex" license = "0BSD" publish = false +[features] +# Support for the async-std executor +async-std = ["dep:async-std"] +default = ["async-std"] + [dependencies] async-mutex = "1.4.0" -async-std = "1.12.0" +async-std = { version = "1.12.0", optional = true } async-trait = "0.1.58" enum_dispatch = "0.3.8" flume = "0.10.14" diff --git a/src/executor.rs b/src/executor.rs index 1f9e3d0..34c0611 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -4,9 +4,11 @@ use std::{convert::Infallible, future::Future}; use async_trait::async_trait; use futures::future::BoxFuture; +#[cfg(feature = "async-std")] pub mod asyncstd; pub mod threads; +#[cfg(feature = "async-std")] pub use asyncstd::AsyncStd; pub use threads::Threads; diff --git a/src/testing_util.rs b/src/testing_util.rs index 79fa482..ad10187 100644 --- a/src/testing_util.rs +++ b/src/testing_util.rs @@ -135,6 +135,7 @@ mod tests { use super::*; use crate::traits::ActorExt; + #[cfg(feature = "async-std")] mod async_math_actor { use futures::StreamExt; diff --git a/src/util/async_actor.rs b/src/util/async_actor.rs index 1a143e5..8d4479c 100644 --- a/src/util/async_actor.rs +++ b/src/util/async_actor.rs @@ -402,7 +402,7 @@ impl Actor for AsyncActor { mod tests { use super::*; use crate::{ - executor::{AsyncStd, Threads}, + executor::Threads, testing_util::{Add, Math, MathEvent, MathEventType, Output, OutputEvent}, util::Collector, }; @@ -509,9 +509,10 @@ mod tests { assert_eq!(collector_out, expected); } + #[cfg(feature = "async-std")] #[async_std::test] async fn smoke_async_std() { - smoke::().await; + smoke::().await; } #[async_std::test] diff --git a/src/util/sync_actor.rs b/src/util/sync_actor.rs index 65759f5..90e4b97 100644 --- a/src/util/sync_actor.rs +++ b/src/util/sync_actor.rs @@ -375,7 +375,7 @@ impl Actor for SyncActor { mod tests { use super::*; use crate::{ - executor::{AsyncStd, Threads}, + executor::Threads, testing_util::{Add, Math, MathEvent, MathEventType, Output, OutputEvent}, util::Collector, }; @@ -471,9 +471,10 @@ mod tests { assert_eq!(collector_out, expected); } + #[cfg(feature = "async-std")] #[test] fn smoke_async_std() { - smoke::(); + smoke::(); } #[test] diff --git a/src/util/wrapped_channels.rs b/src/util/wrapped_channels.rs index abb22d4..aa71601 100644 --- a/src/util/wrapped_channels.rs +++ b/src/util/wrapped_channels.rs @@ -137,7 +137,7 @@ mod tests { use super::*; use crate::{ - executor::{AsyncStd, Executor, Threads}, + executor::{Executor, Threads}, traits::Actor, util::{AsyncActor, WrappedEvent}, }; @@ -203,9 +203,10 @@ mod tests { assert!(res.val == 99 || res.val == 100); } + #[cfg(feature = "async-std")] #[async_std::test] async fn smoke_async_std() { - smoke::().await; + smoke::().await; } #[async_std::test] -- 2.45.2