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