extern crate moirai;
use moirai::{Moirai, Priority};
fn main() {
let runtime = Moirai::new().expect("failed to create Moirai runtime");
let h1 = runtime.spawn_fn(|| (0_u64..1_000).sum::<u64>());
let h2 = runtime.spawn_fn(|| (0_u64..1_000).map(|n| n * n).sum::<u64>());
let h3 = runtime.spawn_fn(|| (1_u64..=10).product::<u64>());
let sum = h1.join().expect("join").expect("task");
let sumsq = h2.join().expect("join").expect("task");
let fact = h3.join().expect("join").expect("task");
println!("sum(0..1000) = {sum}"); println!("sumsq(0..1000) = {sumsq}"); println!("10! = {fact}");
assert_eq!(sum, 499_500);
assert_eq!(sumsq, 332_833_500);
assert_eq!(fact, 3_628_800);
let high = runtime.spawn_fn_with_priority(|| 1_u32, Priority::High);
let low = runtime.spawn_fn_with_priority(|| 0_u32, Priority::Low);
let h = high.join().expect("join").expect("task");
let l = low.join().expect("join").expect("task");
println!("high={h}, low={l}");
assert_eq!(h, 1);
assert_eq!(l, 0);
println!("all task-spawning assertions passed");
}