macro_rules! tasks {
() => { ... };
( $( $task:expr ),* $(,)? ) => { ... };
}Expand description
Macro helper to build a statically typed TaskQueue with the given tasks.
Returns a task queue (equivalent to chaining Tasks::new().push(...)).
ยงExample
use orx_parallel::*;
use std::sync::Mutex;
let numbers = [4, 8, 15, 16, 23, 42];
let sum = Mutex::new(0);
let max = Mutex::new(i32::MIN);
let all_positive = Mutex::new(false);
let tasks = tasks![
|| *sum.lock().unwrap() = numbers.iter().sum(),
|| *max.lock().unwrap() = numbers.iter().copied().max().unwrap(),
|| *all_positive.lock().unwrap() = numbers.iter().all(|&x| x > 0),
];
Pool::global().run_all(tasks);
assert_eq!(*sum.lock().unwrap(), 108);
assert_eq!(*max.lock().unwrap(), 42);
assert!(*all_positive.lock().unwrap());See adhoc_tasks.rs
for a complete example of running independent ad-hoc tasks concurrently.