mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
chore: enable full CI run (#1399)
* update all tests * fix doc examples * misc API tweaks
This commit is contained in:
@@ -10,7 +10,6 @@ use crate::wheel::{self, Wheel};
|
||||
use crate::{Delay, Error};
|
||||
|
||||
use futures_core::ready;
|
||||
use futures_util::future::poll_fn;
|
||||
use slab::Slab;
|
||||
use std::cmp;
|
||||
use std::future::Future;
|
||||
@@ -72,8 +71,10 @@ use std::time::{Duration, Instant};
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// use tokio::timer::{delay_queue, DelayQueue, Error};
|
||||
/// use futures::{try_ready, Async, Poll, Stream};
|
||||
///
|
||||
/// use futures_core::ready;
|
||||
/// use std::collections::HashMap;
|
||||
/// use std::task::{Context, Poll};
|
||||
/// use std::time::Duration;
|
||||
/// # type CacheKey = String;
|
||||
/// # type Value = String;
|
||||
@@ -104,12 +105,13 @@ use std::time::{Duration, Instant};
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// fn poll_purge(&mut self) -> Poll<(), Error> {
|
||||
/// while let Some(entry) = try_ready!(self.expirations.poll()) {
|
||||
/// fn poll_purge(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
|
||||
/// while let Some(res) = ready!(self.expirations.poll_next(cx)) {
|
||||
/// let entry = res?;
|
||||
/// self.entries.remove(entry.get_ref());
|
||||
/// }
|
||||
///
|
||||
/// Ok(Async::Ready(()))
|
||||
/// Poll::Ready(Ok(()))
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
@@ -349,7 +351,9 @@ impl<T> DelayQueue<T> {
|
||||
Key::new(key)
|
||||
}
|
||||
|
||||
/// TODO: Dox... also is the fn signature correct?
|
||||
/// Attempt to pull out the next value of the delay queue, registering the
|
||||
/// current task for wakeup if the value is not yet available, and returning
|
||||
/// None if the queue is exhausted.
|
||||
pub fn poll_next(
|
||||
&mut self,
|
||||
cx: &mut task::Context<'_>,
|
||||
@@ -370,13 +374,6 @@ impl<T> DelayQueue<T> {
|
||||
}))
|
||||
}
|
||||
|
||||
/// TODO: Dox... also is the fn signature correct?
|
||||
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
|
||||
#[allow(clippy::should_implement_trait)] // false positive : https://github.com/rust-lang/rust-clippy/issues/4290
|
||||
pub async fn next(&mut self) -> Option<Result<Expired<T>, Error>> {
|
||||
poll_fn(|cx| self.poll_next(cx)).await
|
||||
}
|
||||
|
||||
/// Insert `value` into the queue set to expire after the requested duration
|
||||
/// elapses.
|
||||
///
|
||||
|
||||
@@ -55,7 +55,7 @@ impl Interval {
|
||||
Interval { delay, duration }
|
||||
}
|
||||
|
||||
/// TODO: dox
|
||||
#[doc(hidden)] // TODO: remove
|
||||
pub fn poll_next(&mut self, cx: &mut task::Context<'_>) -> Poll<Option<Instant>> {
|
||||
// Wait for the delay to be done
|
||||
ready!(Pin::new(&mut self.delay).poll(cx));
|
||||
@@ -72,9 +72,30 @@ impl Interval {
|
||||
Poll::Ready(Some(now))
|
||||
}
|
||||
|
||||
/// TODO: dox
|
||||
/// Completes when the next instant in the interval has been reached.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(async_await)]
|
||||
///
|
||||
/// use tokio::timer::Interval;
|
||||
///
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let mut interval = Interval::new_interval(Duration::from_millis(10));
|
||||
///
|
||||
/// interval.next().await;
|
||||
/// interval.next().await;
|
||||
/// interval.next().await;
|
||||
///
|
||||
/// // approximately 30ms have elapsed.
|
||||
/// }
|
||||
/// ```
|
||||
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
|
||||
#[allow(clippy::should_implement_trait)] // false positive : https://github.com/rust-lang/rust-clippy/issues/4290
|
||||
#[allow(clippy::should_implement_trait)] // TODO: rename (tokio-rs/tokio#1261)
|
||||
pub async fn next(&mut self) -> Option<Instant> {
|
||||
poll_fn(|cx| self.poll_next(cx)).await
|
||||
}
|
||||
|
||||
+25
-18
@@ -31,28 +31,33 @@ use std::time::{Duration, Instant};
|
||||
/// then a timeout should be set on the future that processes the stream. For
|
||||
/// example:
|
||||
///
|
||||
/// ```rust
|
||||
/// // import the `timeout` function, usually this is done
|
||||
/// // with `use tokio::prelude::*`
|
||||
/// use tokio::prelude::FutureExt;
|
||||
/// use futures::Stream;
|
||||
/// use futures::sync::mpsc;
|
||||
/// ```rust,no_run
|
||||
/// #![feature(async_await)]
|
||||
///
|
||||
/// use tokio::prelude::*;
|
||||
/// use tokio::sync::mpsc;
|
||||
///
|
||||
/// use std::thread;
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// let (tx, rx) = mpsc::unbounded();
|
||||
/// # tx.unbounded_send(()).unwrap();
|
||||
/// # drop(tx);
|
||||
/// # async fn dox() {
|
||||
/// let (mut tx, rx) = mpsc::unbounded_channel();
|
||||
///
|
||||
/// thread::spawn(move || {
|
||||
/// tx.try_send(()).unwrap();
|
||||
/// thread::sleep(Duration::from_millis(10));
|
||||
/// tx.try_send(()).unwrap();
|
||||
/// });
|
||||
///
|
||||
/// let process = rx.for_each(|item| {
|
||||
/// // do something with `item`
|
||||
/// # drop(item);
|
||||
/// # Ok(())
|
||||
/// # tokio::future::ready(())
|
||||
/// });
|
||||
///
|
||||
/// # tokio::runtime::current_thread::block_on_all(
|
||||
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
|
||||
/// process.timeout(Duration::from_millis(10))
|
||||
/// # ).unwrap();
|
||||
/// process.timeout(Duration::from_millis(10)).await;
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// # Cancelation
|
||||
@@ -91,18 +96,20 @@ impl<T> Timeout<T> {
|
||||
/// Create a new `Timeout` set to expire in 10 milliseconds.
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(async_await)]
|
||||
///
|
||||
/// use tokio::timer::Timeout;
|
||||
/// use futures::Future;
|
||||
/// use futures::sync::oneshot;
|
||||
/// use tokio::sync::oneshot;
|
||||
///
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// # async fn dox() {
|
||||
/// let (tx, rx) = oneshot::channel();
|
||||
/// # tx.send(()).unwrap();
|
||||
///
|
||||
/// # tokio::runtime::current_thread::block_on_all(
|
||||
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
|
||||
/// Timeout::new(rx, Duration::from_millis(10))
|
||||
/// # ).unwrap();
|
||||
/// Timeout::new(rx, Duration::from_millis(10)).await;
|
||||
/// }
|
||||
/// ```
|
||||
pub fn new(value: T, timeout: Duration) -> Timeout<T> {
|
||||
let delay = Delay::new_timeout(now() + timeout, timeout);
|
||||
|
||||
Reference in New Issue
Block a user