sync: fix will_wake usage in Notify (#4751)

This commit is contained in:
Alice Ryhl 2022-06-06 09:40:40 +02:00 committed by GitHub
parent bac7984417
commit c7280167db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -856,7 +856,7 @@ impl Notified<'_> {
// Update the waker, if necessary.
if let Some(waker) = waker {
let should_update = match w.waker.as_ref() {
Some(current_waker) => current_waker.will_wake(waker),
Some(current_waker) => !current_waker.will_wake(waker),
None => true,
};
if should_update {

View File

@ -207,3 +207,21 @@ fn test_enable_consumes_permit() {
let mut future2 = spawn(notify.notified());
future2.enter(|_, fut| assert!(!fut.enable()));
}
#[test]
fn test_waker_update() {
use futures::task::noop_waker;
use std::future::Future;
use std::task::Context;
let notify = Notify::new();
let mut future = spawn(notify.notified());
let noop = noop_waker();
future.enter(|_, fut| assert_pending!(fut.poll(&mut Context::from_waker(&noop))));
assert_pending!(future.poll());
notify.notify_one();
assert!(future.is_woken());
}