How to use tokio spawn

Use tokio::task::spawn to run async functions concurrently and get a JoinHandle to await their results.

Use tokio::task::spawn to run an async function concurrently on the Tokio runtime, returning a JoinHandle to track its completion.

use tokio::task::spawn;

#[tokio::main]
async fn main() {
    let handle = spawn(async {
        println!("Running in a spawned task");
    });
    handle.await.unwrap();
}

Ensure your Cargo.toml includes tokio with the rt-multi-thread feature enabled.