diff options
| author | hybrid <hybrid@hybridlabs.cc> | 2026-11-07 05:53:30 +0300 |
|---|---|---|
| committer | hybrid <hybrid@hybridlabs.cc> | 2026-11-07 05:53:30 +0300 |
| commit | a3463adee5cfcbc422886653787fee12e594d5f6 (patch) | |
| tree | 10befc5aa83ab2d1abb09862d70cfeef4d82d55d /src/thread2async | |
| parent | 62dcfb1d9f95503f8eb8be1b29fa1d75bfcc27e2 (diff) | |
| download | rust-book-a3463adee5cfcbc422886653787fee12e594d5f6.tar.gz rust-book-a3463adee5cfcbc422886653787fee12e594d5f6.tar.bz2 rust-book-a3463adee5cfcbc422886653787fee12e594d5f6.zip | |
add: streams, thread2async, oop, blog
Diffstat (limited to 'src/thread2async')
| -rw-r--r-- | src/thread2async/Cargo.toml | 7 | ||||
| -rw-r--r-- | src/thread2async/src/main.rs | 23 |
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}"); + } + }); +} |
