externally_driven_async_rt/notify/
notified.rs1use core::{future::Future, pin::Pin, task::Poll};
2
3use crate::notify::Notification;
4
5#[must_use = "futures do nothing unless you `.await` or poll them"]
12pub struct Notified<'ctx> {
13 notification: &'ctx Notification,
14 registered: bool,
15}
16
17impl<'ctx> Notified<'ctx> {
18 pub(crate) const fn new(notification: &'ctx Notification) -> Self {
19 Self {
20 notification,
21 registered: false,
22 }
23 }
24}
25
26impl Future for Notified<'_> {
27 type Output = ();
28
29 fn poll(mut self: Pin<&mut Self>, cx: &mut core::task::Context<'_>) -> Poll<()> {
30 let poll = self.notification.poll(cx.waker());
31 self.registered = poll.is_pending();
32 poll
33 }
34}
35
36impl Drop for Notified<'_> {
37 fn drop(&mut self) {
38 if self.registered {
39 self.notification.forget_waker();
40 }
41 }
42}
43
44impl core::fmt::Debug for Notified<'_> {
45 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
46 f.write_str("Notified")
47 }
48}