mirror of
https://github.com/async-rs/async-std.git
synced 2025-03-04 09:09:41 +00:00
fix: do not require the runtime to use unstable features
This commit is contained in:
parent
0ec027dbff
commit
52c72426c1
4 changed files with 36 additions and 29 deletions
|
@ -29,9 +29,13 @@ default = [
|
||||||
"log",
|
"log",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"smol",
|
||||||
]
|
]
|
||||||
docs = ["attributes", "unstable", "default"]
|
docs = ["attributes", "unstable", "default"]
|
||||||
unstable = ["std"]
|
unstable = [
|
||||||
|
"std",
|
||||||
|
"futures-timer",
|
||||||
|
]
|
||||||
attributes = ["async-attributes"]
|
attributes = ["async-attributes"]
|
||||||
std = [
|
std = [
|
||||||
"alloc",
|
"alloc",
|
||||||
|
@ -42,8 +46,6 @@ std = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
"slab",
|
"slab",
|
||||||
"smol",
|
|
||||||
"futures-timer",
|
|
||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
]
|
]
|
||||||
|
@ -66,6 +68,7 @@ once_cell = { version = "1.3.1", optional = true }
|
||||||
pin-project-lite = { version = "0.1.4", optional = true }
|
pin-project-lite = { version = "0.1.4", optional = true }
|
||||||
pin-utils = { version = "0.1.0-alpha.4", optional = true }
|
pin-utils = { version = "0.1.0-alpha.4", optional = true }
|
||||||
slab = { version = "0.4.2", 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 :/
|
# Devdepencency, but they are not allowed to be optional :/
|
||||||
surf = { version = "1.0.3", optional = true }
|
surf = { version = "1.0.3", optional = true }
|
||||||
|
|
|
@ -61,10 +61,10 @@ cfg_std! {
|
||||||
mod ready;
|
mod ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_default! {
|
#[cfg(any(feature = "unstable", feature = "default"))]
|
||||||
pub use timeout::{timeout, TimeoutError};
|
pub use timeout::{timeout, TimeoutError};
|
||||||
mod timeout;
|
#[cfg(any(feature = "unstable", feature = "default"))]
|
||||||
}
|
mod timeout;
|
||||||
|
|
||||||
cfg_unstable! {
|
cfg_unstable! {
|
||||||
pub use into_future::IntoFuture;
|
pub use into_future::IntoFuture;
|
||||||
|
|
|
@ -168,7 +168,9 @@ cfg_default! {
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_unstable! {
|
cfg_unstable! {
|
||||||
|
#[cfg(feature = "default")]
|
||||||
pub use spawn_local::spawn_local;
|
pub use spawn_local::spawn_local;
|
||||||
|
|
||||||
|
#[cfg(feature = "default")]
|
||||||
mod spawn_local;
|
mod spawn_local;
|
||||||
}
|
}
|
||||||
|
|
46
src/utils.rs
46
src/utils.rs
|
@ -60,36 +60,38 @@ pub(crate) trait Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(not(target_os = "unknown"), feature = "default"))]
|
#[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(all(target_arch = "wasm32", feature = "default"))]
|
|
||||||
impl Timer {
|
|
||||||
pub(crate) fn after(dur: std::time::Duration) -> Self {
|
|
||||||
Timer(futures_timer::Delay::new(dur))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(any(all(target_arch = "wasm32", feature = "default"), feature = "unstable"))]
|
||||||
use std::pin::Pin;
|
mod timer {
|
||||||
#[cfg(target_arch = "wasm32")]
|
use std::pin::Pin;
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[derive(Debug)]
|
||||||
impl std::future::Future for Timer {
|
pub(crate) struct Timer(futures_timer::Delay);
|
||||||
type Output = ();
|
|
||||||
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
|
impl Timer {
|
||||||
match Pin::new(&mut self.0).poll(cx) {
|
pub(crate) fn after(dur: std::time::Duration) -> Self {
|
||||||
Poll::Pending => Poll::Pending,
|
Timer(futures_timer::Delay::new(dur))
|
||||||
Poll::Ready(_) => Poll::Ready(()),
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) use timer::*;
|
||||||
|
|
||||||
/// Defers evaluation of a block of code until the end of the scope.
|
/// Defers evaluation of a block of code until the end of the scope.
|
||||||
#[cfg(feature = "default")]
|
#[cfg(feature = "default")]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|
Loading…
Reference in a new issue