mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
Yield now docs (#2129)
* add subsections for the blocking and yielding examples in task mod * flesh out yield_now rustdoc * add a must_use for yield_now
This commit is contained in:
parent
1475448bdf
commit
bb6c3839ef
@ -122,6 +122,8 @@
|
|||||||
//! Instead, Tokio provides two APIs for running blocking operations in an
|
//! Instead, Tokio provides two APIs for running blocking operations in an
|
||||||
//! asynchronous context: [`task::spawn_blocking`] and [`task::block_in_place`].
|
//! asynchronous context: [`task::spawn_blocking`] and [`task::block_in_place`].
|
||||||
//!
|
//!
|
||||||
|
//! #### spawn_blocking
|
||||||
|
//!
|
||||||
//! The `task::spawn_blocking` function is similar to the `task::spawn` function
|
//! The `task::spawn_blocking` function is similar to the `task::spawn` function
|
||||||
//! discussed in the previous section, but rather than spawning an
|
//! discussed in the previous section, but rather than spawning an
|
||||||
//! _non-blocking_ future on the Tokio runtime, it instead spawns a
|
//! _non-blocking_ future on the Tokio runtime, it instead spawns a
|
||||||
@ -155,6 +157,8 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
//! #### block_in_place
|
||||||
|
//!
|
||||||
//! When using the [threaded runtime][rt-threaded], the [`task::block_in_place`]
|
//! When using the [threaded runtime][rt-threaded], the [`task::block_in_place`]
|
||||||
//! function is also available. Like `task::spawn_blocking`, this function
|
//! function is also available. Like `task::spawn_blocking`, this function
|
||||||
//! allows running a blocking operation from an asynchronous context. Unlike
|
//! allows running a blocking operation from an asynchronous context. Unlike
|
||||||
@ -178,11 +182,14 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! In addition, this module also provides a [`task::yield_now`] async function
|
//! #### yield_now
|
||||||
//! that is analogous to the standard library's [`thread::yield_now`]. Calling and
|
//!
|
||||||
//! `await`ing this function will cause the current task to yield to the Tokio
|
//! In addition, this module provides a [`task::yield_now`] async function
|
||||||
//! runtime's scheduler, allowing another task to be scheduled. Eventually, the
|
//! that is analogous to the standard library's [`thread::yield_now`]. Calling
|
||||||
//! yielding task will be polled again, allowing it to execute. For example:
|
//! and `await`ing this function will cause the current task to yield to the
|
||||||
|
//! Tokio runtime's scheduler, allowing other tasks to be
|
||||||
|
//! scheduled. Eventually, the yielding task will be polled again, allowing it
|
||||||
|
//! to execute. For example:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use tokio::task;
|
//! use tokio::task;
|
||||||
|
@ -3,7 +3,17 @@ use std::pin::Pin;
|
|||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
doc_rt_core! {
|
doc_rt_core! {
|
||||||
/// Yield execution back to the Tokio runtime.
|
/// Return a `Future` that can be `await`-ed to yield execution back to the
|
||||||
|
/// Tokio runtime.
|
||||||
|
///
|
||||||
|
/// A task yields by awaiting the returned `Future`, and may resume when
|
||||||
|
/// that future completes (with no output.) The current task will be
|
||||||
|
/// re-added as a pending task at the _back_ of the pending queue. Any
|
||||||
|
/// other pending tasks will be scheduled. No other waking is required for
|
||||||
|
/// the task to continue.
|
||||||
|
///
|
||||||
|
/// See also the usage example in the [task module](index.html#yield_now).
|
||||||
|
#[must_use = "yield_now does nothing unless polled/`await`-ed"]
|
||||||
pub async fn yield_now() {
|
pub async fn yield_now() {
|
||||||
/// Yield implementation
|
/// Yield implementation
|
||||||
struct YieldNow {
|
struct YieldNow {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user