How to Build a Task Queue in Rust

Build a Rust task queue using trpl::spawn_task to enqueue jobs and trpl::join to process them concurrently.

Build a task queue in Rust by using trpl::spawn_task to enqueue work and trpl::join or handle.await to process results concurrently.

use std::time::Duration;

fn main() {
    trpl::block_on(async {
        let handle = trpl::spawn_task(async {
            for i in 1..10 {
                println!("Task {i} running");
                trpl::sleep(Duration::from_millis(500)).await;
            }
        });

        trpl::join(
            async { println!("Other work"); },
            async { handle.await.unwrap(); }
        ).await;
    });
}