Skip to content

Commit e3a5247

Browse files
committed
notifier: recheck for readiness after registering waker
Make sure we can't lose any event inbetween that small window of time Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
1 parent 7b60b1a commit e3a5247

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/notifier.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ impl Future for Notifier {
3232
type Output = ();
3333

3434
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
35+
if self.ready() {
36+
return Poll::Ready(());
37+
}
38+
self.wakers.register(cx.waker());
39+
// Re-check after registering to close the lost-wakeup window between the
40+
// first check and the waker registration.
3541
if self.ready() {
3642
Poll::Ready(())
3743
} else {
38-
self.wakers.register(cx.waker());
3944
Poll::Pending
4045
}
4146
}

0 commit comments

Comments
 (0)