parallel_tasks/
parallel_tasks.rs

1use avx_async::Runtime;
2use std::time::Duration;
3
4fn main() {
5    let rt = Runtime::new();
6
7    rt.block_on(async move {
8        println!("Spawning 100 concurrent tasks...");
9
10        let mut handles = vec![];
11
12        for i in 0..100 {
13            let handle = rt.spawn_with_handle(async move {
14                avx_async::sleep(Duration::from_millis(10)).await;
15                i * i
16            });
17            handles.push(handle);
18        }
19
20        println!("Waiting for all tasks to complete...");
21
22        let mut sum = 0;
23        for handle in handles {
24            if let Some(result) = handle.await_result().await {
25                sum += result;
26            }
27        }
28
29        println!("Sum of squares from 0 to 99: {}", sum);
30        println!("Active tasks: {}", rt.task_count());
31    });
32}
33
34
35
36
37