mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-27 00:00:12 +02:00
Provide optional features on tokio crate (#808)
Disabling all features means the only dependency is `futures`. Relevant pieces of the API can then be enabled with the following features: - `codec` - `fs` - `io` - `reactor` - `tcp` - `timer` - `udp` - `uds` This also introduces the beginnings of enabling only certain pieces of the `Runtime`. As a start, the entire default runtime API is enabled via the `rt-full` feature.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
#[cfg(feature = "timer")]
|
||||
#[allow(deprecated)]
|
||||
use tokio_timer::Deadline;
|
||||
#[cfg(feature = "timer")]
|
||||
use tokio_timer::Timeout;
|
||||
|
||||
use futures::Future;
|
||||
|
||||
#[cfg(feature = "timer")]
|
||||
use std::time::{Instant, Duration};
|
||||
|
||||
|
||||
@@ -55,12 +58,14 @@ pub trait FutureExt: Future {
|
||||
/// tokio::run(future);
|
||||
/// # }
|
||||
/// ```
|
||||
#[cfg(feature = "timer")]
|
||||
fn timeout(self, timeout: Duration) -> Timeout<Self>
|
||||
where Self: Sized,
|
||||
{
|
||||
Timeout::new(self, timeout)
|
||||
}
|
||||
|
||||
#[cfg(feature = "timer")]
|
||||
#[deprecated(since = "0.1.8", note = "use `timeout` instead")]
|
||||
#[allow(deprecated)]
|
||||
#[doc(hidden)]
|
||||
@@ -78,6 +83,7 @@ mod test {
|
||||
use super::*;
|
||||
use prelude::future;
|
||||
|
||||
#[cfg(feature = "timer")]
|
||||
#[test]
|
||||
fn timeout_polls_at_least_once() {
|
||||
let base_future = future::result::<(), ()>(Ok(()));
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#[cfg(feature = "timer")]
|
||||
use tokio_timer::{
|
||||
throttle::Throttle,
|
||||
Timeout,
|
||||
@@ -5,6 +6,7 @@ use tokio_timer::{
|
||||
|
||||
use futures::Stream;
|
||||
|
||||
#[cfg(feature = "timer")]
|
||||
use std::time::Duration;
|
||||
|
||||
|
||||
@@ -25,6 +27,7 @@ pub trait StreamExt: Stream {
|
||||
/// Throttle down the stream by enforcing a fixed delay between items.
|
||||
///
|
||||
/// Errors are also delayed.
|
||||
#[cfg(feature = "timer")]
|
||||
fn throttle(self, duration: Duration) -> Throttle<Self>
|
||||
where Self: Sized
|
||||
{
|
||||
@@ -63,6 +66,7 @@ pub trait StreamExt: Stream {
|
||||
/// tokio::run(stream);
|
||||
/// # }
|
||||
/// ```
|
||||
#[cfg(feature = "timer")]
|
||||
fn timeout(self, timeout: Duration) -> Timeout<Self>
|
||||
where Self: Sized,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user