mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
447 B
23 lines
447 B
extern crate trpl; // for mdbook test
|
|
|
|
// ANCHOR: all
|
|
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::run(async {
|
|
while let Some(message) = rx.recv().await {
|
|
println!("{message}");
|
|
}
|
|
});
|
|
}
|
|
// ANCHOR_END: all
|