Skip to content

Commit

Permalink
preemption: fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Jan 23, 2020
1 parent 8fafbc6 commit b33ce77
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tokio/src/league/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
//! Consider a future like this one:
//!
//! ```
//! # use tokio::stream::StreamExt;
//! async fn drop_all<I: Stream>(input: I) {
//! # use tokio::stream::{Stream, StreamExt};
//! async fn drop_all<I: Stream + Unpin>(mut input: I) {
//! while let Some(_) = input.next().await {}
//! }
//! ```
Expand All @@ -20,9 +20,9 @@
//! _always_ ready. If we spawn `drop_all`, the task will never yield, and will starve other tasks
//! and resources on the same executor. With opt-in yield points, this problem is alleviated:
//!
//! ```
//! # use tokio::stream::StreamExt;
//! async fn drop_all<I: Stream>(input: I) {
//! ```ignore
//! # use tokio::stream::{Stream, StreamExt};
//! async fn drop_all<I: Stream + Unpin>(mut input: I) {
//! while let Some(_) = input.next().await {
//! tokio::league::cooperate().await;
//! }
Expand All @@ -38,6 +38,8 @@
//! not, a future sufficiently deep in the task hierarchy may end up _never_ getting to run because
//! of the number of yield points that inevitably appear before it is reached.
// NOTE: The doctests in this module are ignored since the whole module is (currently) private.

use std::cell::Cell;
use std::task::{Context, Poll};

Expand Down Expand Up @@ -98,9 +100,9 @@ pub fn poll_cooperate(cx: &mut Context<'_>) -> Poll<()> {
/// deep in the task hierarchy may end up never getting to run because of the number of yield
/// points that inevitably appear before it is even reached. For example:
///
/// ```
/// # use tokio::stream::StreamExt;
/// async fn drop_all<I: Stream>(input: I) {
/// ```ignore
/// # use tokio::stream::{Stream, StreamExt};
/// async fn drop_all<I: Stream + Unpin>(mut input: I) {
/// while let Some(_) = input.next().await {
/// tokio::league::cooperate().await;
/// }
Expand Down

0 comments on commit b33ce77

Please sign in to comment.