From 0462f3685fa619d37cbe7f1e4ef490ad6731d26e Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Fri, 16 Sep 2022 10:44:21 +0200 Subject: [PATCH] tokio-tutorial-jbarszczewski: Hello world Demonstrating async fn and inline async block https://jbarszczewski.com/basics-of-asynchronous-rust-with-tokio --- tokio-tutorial-jbarszczewski/Cargo.toml | 9 +++++++++ tokio-tutorial-jbarszczewski/src/main.rs | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tokio-tutorial-jbarszczewski/Cargo.toml create mode 100644 tokio-tutorial-jbarszczewski/src/main.rs diff --git a/tokio-tutorial-jbarszczewski/Cargo.toml b/tokio-tutorial-jbarszczewski/Cargo.toml new file mode 100644 index 0000000..86cffc6 --- /dev/null +++ b/tokio-tutorial-jbarszczewski/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "tokio-tutorial-jbarszczewski" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = {version = "1.21", features = ["full"]} diff --git a/tokio-tutorial-jbarszczewski/src/main.rs b/tokio-tutorial-jbarszczewski/src/main.rs new file mode 100644 index 0000000..6e69036 --- /dev/null +++ b/tokio-tutorial-jbarszczewski/src/main.rs @@ -0,0 +1,17 @@ +use tokio::join; + +async fn guten_tag() { + println!("Guten Tag!"); +} + +#[tokio::main] +async fn main() { + let task1 = tokio::spawn(async { + println!("Hello, world!"); + }); + let task2 = tokio::spawn(guten_tag()); + + let (r1, r2) = join!(task1, task2); + r1.unwrap(); + r2.unwrap() +} -- 2.39.5