Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some improvements to the async docs #91192

Merged
merged 1 commit into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/core/src/future/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::ops;
use crate::pin::Pin;
use crate::task::{Context, Poll};

/// A future represents an asynchronous computation.
/// A future represents an asynchronous computation obtained by use of [`async`].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be confusing; it isn't only obtained via async since Future is implemented manually for e.g. system resources. Most await chains bottom out in one of these manual implementations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to follow up with another PR.

///
/// A future is a value that might not have finished computing yet. This kind of
/// "asynchronous value" makes it possible for a thread to continue doing useful
Expand All @@ -23,6 +23,7 @@ use crate::task::{Context, Poll};
/// When using a future, you generally won't call `poll` directly, but instead
/// `.await` the value.
///
/// [`async`]: ../../std/keyword.async.html
/// [`Waker`]: crate::task::Waker
#[doc(notable_trait)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
Expand Down
9 changes: 8 additions & 1 deletion library/core/src/future/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#![stable(feature = "futures_api", since = "1.36.0")]

//! Asynchronous values.
//! Asynchronous basic functionality.
//!
//! Please see the fundamental [`async`] and [`await`] keywords and the [async book]
//! for more information on asynchronous programming in Rust.
//!
//! [`async`]: ../../std/keyword.async.html
//! [`await`]: ../../std/keyword.await.html
//! [async book]: https://rust-lang.github.io/async-book/

use crate::{
ops::{Generator, GeneratorState},
Expand Down
14 changes: 8 additions & 6 deletions library/std/src/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2203,37 +2203,39 @@ mod where_keyword {}
///
/// Use `async` in front of `fn`, `closure`, or a `block` to turn the marked code into a `Future`.
/// As such the code will not be run immediately, but will only be evaluated when the returned
/// future is `.await`ed.
/// future is [`.await`]ed.
///
/// We have written an [async book] detailing async/await and trade-offs compared to using threads.
/// We have written an [async book] detailing `async`/`await` and trade-offs compared to using threads.
///
/// ## Editions
///
/// `async` is a keyword from the 2018 edition onwards.
///
/// It is available for use in stable rust from version 1.39 onwards.
/// It is available for use in stable Rust from version 1.39 onwards.
///
/// [`Future`]: future::Future
/// [`.await`]: ../std/keyword.await.html
/// [async book]: https://rust-lang.github.io/async-book/
mod async_keyword {}

#[doc(keyword = "await")]
//
/// Suspend execution until the result of a [`Future`] is ready.
///
/// `.await`ing a future will suspend the current function's execution until the `executor`
/// `.await`ing a future will suspend the current function's execution until the executor
/// has run the future to completion.
///
/// Read the [async book] for details on how async/await and executors work.
/// Read the [async book] for details on how [`async`]/`await` and executors work.
///
/// ## Editions
///
/// `await` is a keyword from the 2018 edition onwards.
///
/// It is available for use in stable rust from version 1.39 onwards.
/// It is available for use in stable Rust from version 1.39 onwards.
///
/// [`Future`]: future::Future
/// [async book]: https://rust-lang.github.io/async-book/
/// [`async`]: ../std/keyword.async.html
mod await_keyword {}

#[doc(keyword = "dyn")]
Expand Down