mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-19 04:33:27 +08:00
Updated 'src/async/all_together.md'.
This commit is contained in:
7
projects/mix_parallel_n_concurrency/Cargo.toml
Normal file
7
projects/mix_parallel_n_concurrency/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "mix_parallel_n_concurrency"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
trpl = "0.3.0"
|
||||
18
projects/mix_parallel_n_concurrency/src/main.rs
Normal file
18
projects/mix_parallel_n_concurrency/src/main.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use std::{thread, time::Duration};
|
||||
|
||||
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}");
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user