advance-practice/select #998
Replies: 3 comments 4 replies
-
use tokio::sync::oneshot;
#[tokio::main]
async fn main() {
let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = oneshot::channel();
tokio::spawn(async {
let _ = tx1.send("one");
});
tokio::spawn(async {
let _ = tx2.send("two");
});
tokio::select! {
val = rx1 => {
println!("rx1 completed first with {:?}", val);
}
val = rx2 => {
println!("rx2 completed first with {:?}", val);
}
}
// 任何一个 select 分支结束后,都会继续执行接下来的代码
} 这段代码async 没有move 为什么能使用,tx1, tx2的生命周期不是比async代码段短吗? |
Beta Was this translation helpful? Give feedback.
4 replies
-
真是要再次吐槽 Pin, 一个 !Unpin 的已经在语言层面 pin 住的东西, 要变成 unpin 居然要使用 Pin. |
Beta Was this translation helpful? Give feedback.
0 replies
-
友情提醒 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
advance-practice/select
https://course.rs/advance-practice/select.html
Beta Was this translation helpful? Give feedback.
All reactions