Skip to content

Commit

Permalink
sync: fix will_wake usage in Notify (#4751)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Jun 6, 2022
1 parent bac7984 commit c728016
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tokio/src/sync/notify.rs
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions tokio/tests/sync_notify.rs
Expand Up @@ -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());
}

0 comments on commit c728016

Please sign in to comment.