mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-20 14:54:47 -07:00
21 lines
608 B
Rust
21 lines
608 B
Rust
/// Imports multiple items in parallel using thread::scope.
|
|
/// Each expression must return Result<T>.
|
|
///
|
|
/// # Example
|
|
/// ```ignore
|
|
/// let (a, b, c) = parallel_import! {
|
|
/// a = SomeVec::forced_import(&db, version),
|
|
/// b = OtherVec::forced_import(&db, version),
|
|
/// c = ThirdVec::forced_import(&db, version),
|
|
/// };
|
|
/// ```
|
|
#[macro_export]
|
|
macro_rules! parallel_import {
|
|
($($name:ident = $expr:expr),+ $(,)?) => {{
|
|
std::thread::scope(|s| -> brk_error::Result<_> {
|
|
$(let $name = s.spawn(|| $expr);)+
|
|
Ok(($($name.join().unwrap()?,)+))
|
|
})?
|
|
}};
|
|
}
|