Make the wakers work

This commit is contained in:
Aode (lion) 2022-03-07 20:03:10 -06:00
parent 6517330ab3
commit 1f7b5f96f8

View file

@ -49,6 +49,14 @@ impl<T: Future> SelectState<T> {
fn check_for_poll(&self) -> bool {
self.woken.swap(false, Ordering::AcqRel)
}
fn waker(&self, parent: Waker) -> Waker {
Arc::new(SelectWaker {
woken: Arc::clone(&self.woken),
parent,
})
.into()
}
}
impl Wake for SelectWaker {
@ -73,13 +81,17 @@ where
let this = self.get_mut();
if this.left.check_for_poll() {
if let Poll::Ready(out) = Pin::new(&mut this.left.future).poll(cx) {
let waker = this.left.waker(cx.waker().clone());
let mut context = Context::from_waker(&waker);
if let Poll::Ready(out) = Pin::new(&mut this.left.future).poll(&mut context) {
return Poll::Ready(Either::Left(out));
}
}
if this.right.check_for_poll() {
if let Poll::Ready(out) = Pin::new(&mut this.right.future).poll(cx) {
let waker = this.right.waker(cx.waker().clone());
let mut context = Context::from_waker(&waker);
if let Poll::Ready(out) = Pin::new(&mut this.right.future).poll(&mut context) {
return Poll::Ready(Either::Right(out));
}
}