tokio-tutorial-jbarszczewski: Hello world
authorMartin Pitt <martin@piware.de>
Fri, 16 Sep 2022 08:44:21 +0000 (10:44 +0200)
committerMartin Pitt <martin@piware.de>
Fri, 16 Sep 2022 09:53:58 +0000 (11:53 +0200)
Demonstrating async fn and inline async block

https://jbarszczewski.com/basics-of-asynchronous-rust-with-tokio

tokio-tutorial-jbarszczewski/Cargo.toml [new file with mode: 0644]
tokio-tutorial-jbarszczewski/src/main.rs [new file with mode: 0644]

diff --git a/tokio-tutorial-jbarszczewski/Cargo.toml b/tokio-tutorial-jbarszczewski/Cargo.toml
new file mode 100644 (file)
index 0000000..86cffc6
--- /dev/null
@@ -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 (file)
index 0000000..6e69036
--- /dev/null
@@ -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()
+}