diff options
Diffstat (limited to 'src/sync.rs')
| -rw-r--r-- | src/sync.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/sync.rs b/src/sync.rs new file mode 100644 index 0000000..08bcce3 --- /dev/null +++ b/src/sync.rs @@ -0,0 +1,30 @@ +use std::task::{Context, Poll, Waker}; + +pub struct Signal{ + waker: Option<Waker>, + active: bool, +} +impl Signal{ + pub fn new() -> Self{ + Self{ + waker: None, + active: false, + } + } + pub fn wake(&mut self){ + self.active = true; + if let Some(w) = self.waker.take(){ + w.wake(); + } + } + pub fn poll(&mut self, ctx: &mut Context<'_>) -> Poll<()>{ + if self.active{ + self.active = false; + Poll::Ready(()) + }else{ + self.waker = Some(ctx.waker().clone()); + Poll::Pending + } + } +} + |
