Skip to content

Commit 631105b

Browse files
Merge pull request #806 from async-rs/fix-feature-unstable
2 parents 0897b91 + 8389041 commit 631105b

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

Diff for: Cargo.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ default = [
2929
"log",
3030
"num_cpus",
3131
"pin-project-lite",
32+
"smol",
3233
]
3334
docs = ["attributes", "unstable", "default"]
34-
unstable = ["std"]
35+
unstable = [
36+
"std",
37+
"futures-timer",
38+
]
3539
attributes = ["async-attributes"]
3640
std = [
3741
"alloc",
@@ -42,8 +46,6 @@ std = [
4246
"once_cell",
4347
"pin-utils",
4448
"slab",
45-
"smol",
46-
"futures-timer",
4749
"wasm-bindgen-futures",
4850
"futures-channel",
4951
]
@@ -67,6 +69,7 @@ once_cell = { version = "1.3.1", optional = true }
6769
pin-project-lite = { version = "0.1.4", optional = true }
6870
pin-utils = { version = "0.1.0-alpha.4", optional = true }
6971
slab = { version = "0.4.2", optional = true }
72+
futures-timer = { version = "3.0.2", optional = true }
7073

7174
# Devdepencency, but they are not allowed to be optional :/
7275
surf = { version = "1.0.3", optional = true }

Diff for: src/future/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ cfg_std! {
6161
mod ready;
6262
}
6363

64-
cfg_default! {
65-
pub use timeout::{timeout, TimeoutError};
66-
mod timeout;
67-
}
64+
#[cfg(any(feature = "unstable", feature = "default"))]
65+
pub use timeout::{timeout, TimeoutError};
66+
#[cfg(any(feature = "unstable", feature = "default"))]
67+
mod timeout;
6868

6969
cfg_unstable! {
7070
pub use into_future::IntoFuture;

Diff for: src/task/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ cfg_default! {
168168
}
169169

170170
cfg_unstable! {
171+
#[cfg(feature = "default")]
171172
pub use spawn_local::spawn_local;
172173

174+
#[cfg(feature = "default")]
173175
mod spawn_local;
174176
}

Diff for: src/utils.rs

+27-21
Original file line numberDiff line numberDiff line change
@@ -60,36 +60,42 @@ pub(crate) trait Context {
6060
}
6161

6262
#[cfg(all(not(target_os = "unknown"), feature = "default"))]
63-
pub(crate) type Timer = smol::Timer;
63+
mod timer {
64+
pub type Timer = smol::Timer;
65+
}
6466

65-
#[cfg(all(target_arch = "wasm32", feature = "default"))]
66-
#[derive(Debug)]
67-
pub(crate) struct Timer(futures_timer::Delay);
67+
#[cfg(any(
68+
all(target_arch = "wasm32", feature = "default"),
69+
all(feature = "unstable", not(feature = "default"))
70+
))]
71+
mod timer {
72+
use std::pin::Pin;
73+
use std::task::Poll;
6874

69-
#[cfg(all(target_arch = "wasm32", feature = "default"))]
70-
impl Timer {
71-
pub(crate) fn after(dur: std::time::Duration) -> Self {
72-
Timer(futures_timer::Delay::new(dur))
73-
}
74-
}
75+
#[derive(Debug)]
76+
pub(crate) struct Timer(futures_timer::Delay);
7577

76-
#[cfg(target_arch = "wasm32")]
77-
use std::pin::Pin;
78-
#[cfg(target_arch = "wasm32")]
79-
use std::task::Poll;
78+
impl Timer {
79+
pub(crate) fn after(dur: std::time::Duration) -> Self {
80+
Timer(futures_timer::Delay::new(dur))
81+
}
82+
}
8083

81-
#[cfg(target_arch = "wasm32")]
82-
impl std::future::Future for Timer {
83-
type Output = ();
84+
impl std::future::Future for Timer {
85+
type Output = ();
8486

85-
fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
86-
match Pin::new(&mut self.0).poll(cx) {
87-
Poll::Pending => Poll::Pending,
88-
Poll::Ready(_) => Poll::Ready(()),
87+
fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
88+
match Pin::new(&mut self.0).poll(cx) {
89+
Poll::Pending => Poll::Pending,
90+
Poll::Ready(_) => Poll::Ready(()),
91+
}
8992
}
9093
}
9194
}
9295

96+
#[cfg(any(feature = "unstable", feature = "default"))]
97+
pub(crate) use timer::*;
98+
9399
/// Defers evaluation of a block of code until the end of the scope.
94100
#[cfg(feature = "default")]
95101
#[doc(hidden)]

0 commit comments

Comments
 (0)