Skip to main content

try_join

Macro try_join 

Source
macro_rules! try_join {
    () => { ... };
    (biased; $($future:expr),+ $(,)?) => { ... };
    ($($future:expr),+ $(,)?) => { ... };
}
Expand description

Waits on every future given, all at once, each giving a Result with the same error type, and gives Ok with their outputs as a tuple in the order written, or the first error.

On the first Err, try_join! gives it at once and drops the other futures. Otherwise it runs as join! does: concurrently, in the awaiting task, polled from one later each time or in order after biased;. try_join!() is Ok(()).

ยงExamples

let ok: Result<(u8, u16), &str> = nuclei::try_join!(async { Ok(1) }, async { Ok(2) });
assert_eq!(ok, Ok((1, 2)));

let failed: Result<(u8, ()), &str> =
    nuclei::try_join!(async { Err("first") }, std::future::pending::<Result<(), &str>>());
assert_eq!(failed, Err("first"));