在一个时雄项目中,我想同时等待SIGTERM
和SIGINT
只需等待其中一个信号即可正常工作:
tracing::debug!("Waiting for the end of the world");
signal(SignalKind::terminate())?.recv().await;
但当我尝试使用www.example.com中this answer的tokio::select!
时users.rustlang.org
use tokio::signal::unix::{signal, SignalKind};
tokio::select! {
_ = signal(SignalKind::interrupt())?.recv() => println!("SIGINT"),
_ = signal(SignalKind::terminate())?.recv() => println!("SIGTERM"),
}
println!("terminating the process...");
我收到一个关于释放仍在使用中的临时变量的错误。
error[E0716]: temporary value dropped while borrowed
--> src/main.rs:495:13
|
494 | let ans = tokio::select! {
| _______________-
495 | | _ = signal(SignalKind::interrupt())?.recv() => println!("SIGINT"),
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
496 | | _ = signal(SignalKind::terminate())?.recv() => println!("SIGTERM"),
497 | | };
| | -
| | |
| |_____temporary value is freed at the end of this statement
| borrow might be used here, when `futures` is dropped and runs the destructor for type `(impl futures_util::Future<Output = std::option::Option<()>>, impl futures_util::Future<Output = std::option::Option<()>>)`
这还能用吗?
1条答案
按热度按时间pftdvrlh1#
问题中引用的例子有一个小错误。如果
Result<Signal>
来自signal
是在select!
宏之外处理的,则没有临时变量可以超过其借用的作用域。