Skip to content

the documentation for the Future trait specifies invariants that are not always true #125050

@lolbinarycat

Description

@lolbinarycat

Location

https://doc.rust-lang.org/std/future/trait.Future.html

Summary

A future represents an asynchronous computation obtained by use of async.

this is not always true, a future represents a value that can be joined into an async function using await, however futures can be returned by non-async functions, such as tokio::task::spawn

Runtime characteristics

Futures alone are inert; they must be actively polled to make progress, meaning that each time the current task is woken up, it should actively re-poll pending futures that it still has an interest in.

once again, this is true for futures created by calling async functions, but may not be true for all types that implement the Future trait, such as tokio::task::JoinHandle.

the distinction between futures that are and are not inert is important, an array of task::JoinHandle is useful for performing several operations concurrently, however an array of futures created by calling async functions will not result in concurrent execution if they are awaited sequentially.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.E-help-wantedCall for participation: Help is requested to fix this issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions