mirror of https://github.com/KaiserY/trpl-zh-cn
28 lines
640 B
28 lines
640 B
6 months ago
|
extern crate trpl; // required for mdbook test
|
||
|
|
||
|
use std::time::Duration;
|
||
|
|
||
|
fn main() {
|
||
|
trpl::run(async {
|
||
|
// ANCHOR: many-messages
|
||
|
let (tx, mut rx) = trpl::channel();
|
||
|
|
||
|
let vals = vec![
|
||
|
String::from("hi"),
|
||
|
String::from("from"),
|
||
|
String::from("the"),
|
||
|
String::from("future"),
|
||
|
];
|
||
|
|
||
|
for val in vals {
|
||
|
tx.send(val).unwrap();
|
||
|
trpl::sleep(Duration::from_millis(500)).await;
|
||
|
}
|
||
|
|
||
|
while let Some(value) = rx.recv().await {
|
||
|
println!("received '{value}'");
|
||
|
}
|
||
|
// ANCHOR_END: many-messages
|
||
|
});
|
||
|
}
|