summaryrefslogtreecommitdiffstats
path: root/src/thread2async
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread2async')
-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}");
+ }
+ });
+}