From: Martin Pitt Date: Fri, 16 Sep 2022 08:44:21 +0000 (+0200) Subject: tokio-tutorial-jbarszczewski: Hello world X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;h=0462f3685fa619d37cbe7f1e4ef490ad6731d26e;p=learn-rust.git tokio-tutorial-jbarszczewski: Hello world Demonstrating async fn and inline async block https://jbarszczewski.com/basics-of-asynchronous-rust-with-tokio --- 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() +}