blob: 08bcce341f3360d597691a166da20e05c61466ce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}
}
}
|