summaryrefslogtreecommitdiffstats
path: root/src/thread2async
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.cc>2026-11-07 05:53:30 +0300
committerhybrid <hybrid@hybridlabs.cc>2026-11-07 05:53:30 +0300
commita3463adee5cfcbc422886653787fee12e594d5f6 (patch)
tree10befc5aa83ab2d1abb09862d70cfeef4d82d55d /src/thread2async
parent62dcfb1d9f95503f8eb8be1b29fa1d75bfcc27e2 (diff)
downloadrust-book-a3463adee5cfcbc422886653787fee12e594d5f6.tar.gz
rust-book-a3463adee5cfcbc422886653787fee12e594d5f6.tar.bz2
rust-book-a3463adee5cfcbc422886653787fee12e594d5f6.zip
add: streams, thread2async, oop, blog
Diffstat (limited to '')
-rw-r--r--src/thread2async/Cargo.toml7
-rw-r--r--src/thread2async/src/main.rs23
2 files changed, 30 insertions, 0 deletions
diff --git a/src/thread2async/Cargo.toml b/src/thread2async/Cargo.toml
new file mode 100644
index 0000000..c9083e3
--- /dev/null
+++ b/src/thread2async/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "thread2async"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+trpl = "0.3.0"
diff --git a/src/thread2async/src/main.rs b/src/thread2async/src/main.rs
new file mode 100644
index 0000000..ccc3edb
--- /dev/null
+++ b/src/thread2async/src/main.rs
@@ -0,0 +1,23 @@
+use std::{
+ thread,
+ time::Duration,
+};
+
+use trpl;
+
+fn main() {
+ let (tx, mut rx) = trpl::channel();
+
+ thread::spawn(move || {
+ for i in 1..11 {
+ tx.send(i).unwrap();
+ thread::sleep(Duration::from_secs(1));
+ }
+ });
+
+ trpl::block_on(async {
+ while let Some(message) = rx.recv().await {
+ println!("{message}");
+ }
+ });
+}