1
0
Fork 0
forked from wry/wry

autocommit 2022-02-24 16:30:11 CET

This commit is contained in:
Julian Orth 2022-02-24 16:30:11 +01:00
parent 666e475032
commit 7d28d30666
39 changed files with 1670 additions and 209 deletions

View file

@ -39,6 +39,10 @@ impl<T> AsyncQueue<T> {
AsyncQueuePop { queue: self }
}
pub fn non_empty<'a>(&'a self) -> AsyncQueueNonEmpty<'a, T> {
AsyncQueueNonEmpty { queue: self }
}
pub fn clear(&self) {
mem::take(&mut *self.data.borrow_mut());
self.waiter.take();
@ -61,3 +65,20 @@ impl<'a, T> Future for AsyncQueuePop<'a, T> {
}
}
}
pub struct AsyncQueueNonEmpty<'a, T> {
queue: &'a AsyncQueue<T>,
}
impl<'a, T> Future for AsyncQueueNonEmpty<'a, T> {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.queue.data.borrow_mut().len() > 0 {
Poll::Ready(())
} else {
self.queue.waiter.set(Some(cx.waker().clone()));
Poll::Pending
}
}
}