expression
try_join!: propagate a branch error
For directly owned Result-producing futures, stop waiting when an error is returned, dropping the unfinished branches. A successful result contains every successful value. This does not roll back earlier side effects or automatically cancel spawned tasks. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): (2, 3) bad Common mistake: Treating early error return as transactional rollback.
Formal Syntax & Structure
rust syntaxrust
tokio::try_join!(future_a, future_b)Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() { let success = tokio::try_join!(async { Ok::<_, &str>(2) }, async { Ok::<_, &str>(3) }); println!("{:?}", success.unwrap()); let error = tokio::try_join!(async { Err::<u32, _>("bad") }, std::future::pending::<Result<u32, &str>>()); println!("{}", error.unwrap_err());}