trpl-zh-cn/listings/ch17-async-await/listing-17-09/src/main.rs

16 lines
351 B
Rust
Raw Normal View History

2024-10-20 23:44:05 +08:00
extern crate trpl; // required for mdbook test
fn main() {
trpl::run(async {
// ANCHOR: channel
let (tx, mut rx) = trpl::channel();
let val = String::from("hi");
tx.send(val).unwrap();
let received = rx.recv().await.unwrap();
println!("Got: {received}");
// ANCHOR_END: channel
});
}