Skip to content

Commit fc9091c

Browse files
author
Stjepan Glavina
committed
Put futues::timeout behind unstable feature
1 parent 8be2ebc commit fc9091c

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ before_script:
2323
- cargo install-update -a
2424

2525
script:
26-
- if ![[ -n "$BUILD_BOOK" ]]; then cargo check --all --benches --bins --examples --tests && cargo test --all; fi
27-
- if [[ -n "$BUILD_BOOK" ]]; then cargo test --all --benches --bins --examples --tests; fi
26+
- if ![[ -n "$BUILD_BOOK" ]]; then cargo check --features unstable --all --benches --bins --examples --tests && cargo test --features unstable --all; fi
27+
- if [[ -n "$BUILD_BOOK" ]]; then cargo test --features unstable --all --benches --bins --examples --tests; fi
2828
- cargo fmt --all -- --check
2929
- if [[ -n "$BUILD_DOCS" ]]; then cargo doc --features docs; fi
3030
- if [[ -n "$BUILD_BOOK" ]]; then mdbook build docs && mdbook test -L ./target/debug/deps docs; fi

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rustdoc-args = ["--cfg", "feature=\"docs\""]
2121

2222
[features]
2323
docs = []
24+
unstable = []
2425

2526
[dependencies]
2627
async-task = "1.0.0"

src/future/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
#[doc(inline)]
44
pub use std::future::Future;
55

6+
use cfg_if::cfg_if;
7+
68
pub use pending::pending;
79
pub use ready::ready;
8-
pub use timeout::{timeout, TimeoutError};
910

1011
mod pending;
1112
mod ready;
12-
mod timeout;
13+
14+
cfg_if! {
15+
if #[cfg(any(feature = "unstable", feature = "docs"))] {
16+
mod timeout;
17+
pub use timeout::{timeout, TimeoutError};
18+
}
19+
}

src/future/timeout.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::pin::Pin;
44
use std::time::Duration;
55

66
use futures_timer::Delay;
7-
use pin_utils::unsafe_pinned;
87

98
use crate::future::Future;
109
use crate::task::{Context, Poll};
@@ -14,7 +13,6 @@ use crate::task::{Context, Poll};
1413
/// # Examples
1514
///
1615
/// ```
17-
/// # #![feature(async_await)]
1816
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
1917
/// #
2018
/// use std::time::Duration;
@@ -27,6 +25,7 @@ use crate::task::{Context, Poll};
2725
/// #
2826
/// # Ok(()) }) }
2927
/// ```
28+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
3029
pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError>
3130
where
3231
F: Future<Output = T>,
@@ -47,8 +46,8 @@ struct TimeoutFuture<F> {
4746
}
4847

4948
impl<F> TimeoutFuture<F> {
50-
unsafe_pinned!(future: F);
51-
unsafe_pinned!(delay: Delay);
49+
pin_utils::unsafe_pinned!(future: F);
50+
pin_utils::unsafe_pinned!(delay: Delay);
5251
}
5352

5453
impl<F: Future> Future for TimeoutFuture<F> {
@@ -58,16 +57,19 @@ impl<F: Future> Future for TimeoutFuture<F> {
5857
match self.as_mut().future().poll(cx) {
5958
Poll::Ready(v) => Poll::Ready(Ok(v)),
6059
Poll::Pending => match self.delay().poll(cx) {
61-
Poll::Ready(_) => Poll::Ready(Err(TimeoutError)),
60+
Poll::Ready(_) => Poll::Ready(Err(TimeoutError { _priv: () })),
6261
Poll::Pending => Poll::Pending,
6362
},
6463
}
6564
}
6665
}
6766

6867
/// An error returned when a future times out.
68+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
6969
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
70-
pub struct TimeoutError;
70+
pub struct TimeoutError {
71+
_priv: (),
72+
}
7173

7274
impl Error for TimeoutError {}
7375

0 commit comments

Comments
 (0)