diff options
author | Carl Lerche <me@carllerche.com> | 2020-01-22 18:59:22 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-22 18:59:22 -0800 |
commit | 8cf98d694663e8397bfc337e7a4676567287bfae (patch) | |
tree | 50b214c2e29a257633494a64eed35c5b6f568eba /tokio/src/lib.rs | |
parent | f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b (diff) |
Provide `select!` macro (#2152)
Provides a `select!` macro for concurrently waiting on multiple async
expressions. The macro has similar goals and syntax as the one provided
by the `futures` crate, but differs significantly in implementation.
First, this implementation does not require special traits to be
implemented on futures or streams (i.e., no `FuseFuture`). A design goal
is to be able to pass a "plain" async fn result into the select! macro.
Even without `FuseFuture`, this `select!` implementation is able to
handle all cases the `futures::select!` macro can handle. It does this
by supporting pre-poll conditions on branches and result pattern
matching. For pre-conditions, each branch is able to include a condition
that disables the branch if it evaluates to false. This allows the user
to guard futures that have already been polled, preventing double
polling. Pattern matching can be used to disable streams that complete.
A second big difference is the macro is implemented almost entirely as a
declarative macro. The biggest advantage to using this strategy is that
the user will not need to alter the rustc recursion limit except in the
most extreme cases.
The resulting future also tends to be smaller in many cases.
Diffstat (limited to 'tokio/src/lib.rs')
-rw-r--r-- | tokio/src/lib.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index 42a34131..7989d5b3 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -282,15 +282,20 @@ //! } //! ``` -// macros used internally +// Includes re-exports used by macros. +// +// This module is not intended to be part of the public API. In general, any +// `doc(hidden)` code is not part of Tokio's public and stable API. #[macro_use] -mod macros; +#[doc(hidden)] +pub mod macros; cfg_fs! { pub mod fs; } -mod future; +#[doc(hidden)] +pub mod future; pub mod io; pub mod net; @@ -333,6 +338,12 @@ cfg_time! { mod util; cfg_macros! { + /// Implementation detail of the `select!` macro. This macro is **not** + /// intended to be used as part of the public API and is permitted to + /// change. + #[doc(hidden)] + pub use tokio_macros::select_priv_declare_output_enum; + doc_rt_core! { cfg_rt_threaded! { #[cfg(not(test))] // Work around for rust-lang/rust#62127 |