macro_rules! join_all {
() => { ... };
($error_handler:expr) => { ... };
}Expand description
Joins all pending threads spawned from the current thread by either go! or go_ref!.
Threads will be joined starting with the most recent and working backwards until the earliest thread spawned.
§Handling panics
join_all optionally takes a callback to invoke on the error values returned when joining
threads that panicked. The callback will be invoked on each error value returned when joining
threads before proceeding to join the next thread, so it’s recommended to avoid doing heavy
work in these error handlers (e.g. by using a channel to pass the error somewhere else to be
processed).
See the documentation for JoinHandle::join for more details.
§Examples
use go_spawn::{go, go_ref, join_all};
use std::sync::{
atomic::{AtomicI64, Ordering},
};
static COUNTER: AtomicI64 = AtomicI64::new(0);
for _ in 0..4 {
go_ref! {
COUNTER.fetch_add(1, Ordering::SeqCst);
}
}
join_all!();
assert_eq!(COUNTER.load(Ordering::SeqCst), 4);
for i in 0_i64..4 {
go! {
std::panic::panic_any(i);
}
}
static ERR_COUNTER: AtomicI64 = AtomicI64::new(0);
join_all!(|error| {
let value: &i64 = error.downcast_ref().unwrap();
assert_eq!(ERR_COUNTER.fetch_add(1, Ordering::SeqCst), *value);
});