Skip to content

fix: do not require the runtime to use unstable features #806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -29,9 +29,13 @@ default = [
"log",
"num_cpus",
"pin-project-lite",
"smol",
]
docs = ["attributes", "unstable", "default"]
unstable = ["std"]
unstable = [
"std",
"futures-timer",
]
attributes = ["async-attributes"]
std = [
"alloc",
@@ -42,8 +46,6 @@ std = [
"once_cell",
"pin-utils",
"slab",
"smol",
"futures-timer",
"wasm-bindgen-futures",
"futures-channel",
]
@@ -66,6 +68,7 @@ once_cell = { version = "1.3.1", optional = true }
pin-project-lite = { version = "0.1.4", optional = true }
pin-utils = { version = "0.1.0-alpha.4", optional = true }
slab = { version = "0.4.2", optional = true }
futures-timer = { version = "3.0.2", optional = true }

# Devdepencency, but they are not allowed to be optional :/
surf = { version = "1.0.3", optional = true }
8 changes: 4 additions & 4 deletions src/future/mod.rs
Original file line number Diff line number Diff line change
@@ -61,10 +61,10 @@ cfg_std! {
mod ready;
}

cfg_default! {
pub use timeout::{timeout, TimeoutError};
mod timeout;
}
#[cfg(any(feature = "unstable", feature = "default"))]
pub use timeout::{timeout, TimeoutError};
#[cfg(any(feature = "unstable", feature = "default"))]
mod timeout;

cfg_unstable! {
pub use into_future::IntoFuture;
2 changes: 2 additions & 0 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
@@ -168,7 +168,9 @@ cfg_default! {
}

cfg_unstable! {
#[cfg(feature = "default")]
pub use spawn_local::spawn_local;

#[cfg(feature = "default")]
mod spawn_local;
}
48 changes: 27 additions & 21 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -60,36 +60,42 @@ pub(crate) trait Context {
}

#[cfg(all(not(target_os = "unknown"), feature = "default"))]
pub(crate) type Timer = smol::Timer;
mod timer {
pub type Timer = smol::Timer;
}

#[cfg(all(target_arch = "wasm32", feature = "default"))]
#[derive(Debug)]
pub(crate) struct Timer(futures_timer::Delay);
#[cfg(any(
all(target_arch = "wasm32", feature = "default"),
all(feature = "unstable", not(feature = "default"))
))]
mod timer {
use std::pin::Pin;
use std::task::Poll;

#[cfg(all(target_arch = "wasm32", feature = "default"))]
impl Timer {
pub(crate) fn after(dur: std::time::Duration) -> Self {
Timer(futures_timer::Delay::new(dur))
}
}
#[derive(Debug)]
pub(crate) struct Timer(futures_timer::Delay);

#[cfg(target_arch = "wasm32")]
use std::pin::Pin;
#[cfg(target_arch = "wasm32")]
use std::task::Poll;
impl Timer {
pub(crate) fn after(dur: std::time::Duration) -> Self {
Timer(futures_timer::Delay::new(dur))
}
}

#[cfg(target_arch = "wasm32")]
impl std::future::Future for Timer {
type Output = ();
impl std::future::Future for Timer {
type Output = ();

fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
match Pin::new(&mut self.0).poll(cx) {
Poll::Pending => Poll::Pending,
Poll::Ready(_) => Poll::Ready(()),
fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
match Pin::new(&mut self.0).poll(cx) {
Poll::Pending => Poll::Pending,
Poll::Ready(_) => Poll::Ready(()),
}
}
}
}

#[cfg(any(feature = "unstable", feature = "default"))]
pub(crate) use timer::*;

/// Defers evaluation of a block of code until the end of the scope.
#[cfg(feature = "default")]
#[doc(hidden)]