|
1 | 1 | //! Asynchronous values.
|
| 2 | +//! |
| 3 | +//! ## Base Futures Concurrency |
| 4 | +//! |
| 5 | +//! Often it's desireable to await multiple futures as if it was a single |
| 6 | +//! future. The `join` family of operations converts multiple futures into a |
| 7 | +//! single future that returns all of their outputs. The `select` family of |
| 8 | +//! operations converts multiple future into a single future that returns the |
| 9 | +//! first output. |
| 10 | +//! |
| 11 | +//! For operating on futures the following macros can be used: |
| 12 | +//! |
| 13 | +//! | Name | Return signature | When does it return? | |
| 14 | +//! | --- | --- | --- | |
| 15 | +//! | `future::join` | `(T1, T2)` | Wait for all to complete |
| 16 | +//! | `future::select` | `T` | Return on first value |
| 17 | +//! |
| 18 | +//! ## Fallible Futures Concurrency |
| 19 | +//! |
| 20 | +//! For operating on futures that return `Result` additional `try_` variants of |
| 21 | +//! the macros mentioned before can be used. These macros are aware of `Result`, |
| 22 | +//! and will behave slightly differently from their base variants. |
| 23 | +//! |
| 24 | +//! In the case of `try_join`, if any of the futures returns `Err` all |
| 25 | +//! futures are dropped and an error is returned. This is referred to as |
| 26 | +//! "short-circuiting". |
| 27 | +//! |
| 28 | +//! In the case of `try_select`, instead of returning the first future that |
| 29 | +//! completes it returns the first future that _successfully_ completes. This |
| 30 | +//! means `try_select` will keep going until any one of the futures returns |
| 31 | +//! `Ok`, or _all_ futures have returned `Err`. |
| 32 | +//! |
| 33 | +//! However sometimes it can be useful to use the base variants of the macros |
| 34 | +//! even on futures that return `Result`. Here is an overview of operations that |
| 35 | +//! work on `Result`, and their respective semantics: |
| 36 | +//! |
| 37 | +//! | Name | Return signature | When does it return? | |
| 38 | +//! | --- | --- | --- | |
| 39 | +//! | `future::join` | `(Result<T, E>, Result<T, E>)` | Wait for all to complete |
| 40 | +//! | `future::try_join` | `Result<(T1, T2), E>` | Return on first `Err`, wait for all to complete |
| 41 | +//! | `future::select` | `Result<T, E>` | Return on first value |
| 42 | +//! | `future::try_select` | `Result<T, E>` | Return on first `Ok`, reject on last Err |
2 | 43 |
|
3 | 44 | #[doc(inline)]
|
4 | 45 | pub use std::future::Future;
|
|
0 commit comments