Open ybbh opened 2 weeks ago
Your program sleeps forever for the same reason as this program:
use tokio::sync::Notify;
#[tokio::main]
async fn main() {
let notify = Notify::new();
notify.notify_waiters();
notify.notified().await;
// never reaches this line
}
It has nothing to do with being inside/outside the runtime.
Version List the versions of all
tokio
crates you are using.cargo tree | grep tokio
Platform The output of
uname -a
(UNIX), or version and 32 or 64-bit (Windows)Description
If notify() is invoked prior to notfied().await, then the call to notified().await will result in perpetual blocking without the possibility of being notified.
I tried this code:
I expected to see this happen:
The call to notified().await should be notified. Or if it is unsafe to invoke notify() before notified().await, this should be clearly documented to avoid potential issues.
Instead, this happened:
The call to notified().await cannot be notified.