File: thread_executor_arc.rs

package info (click to toggle)
rust-smol-macros 0.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 540 bytes parent folder | download
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
//! Set up a thread executor.

use smol_macros::{main, Executor};
use std::sync::Arc;
use std::time::Duration;

main! {
    async fn main(ex: Arc<Executor<'_>>) {
        let mut tasks = vec![];
        for i in 0..16 {
            let task = ex.spawn(async move {
                println!("Task number {i}");
            });

            tasks.push(task);
        }

        async_io::Timer::after(Duration::from_secs(1)).await;

        // Wait for tasks to complete.
        for task in tasks {
            task.await;
        }
    }
}