autocommit 2022-02-24 16:30:11 CET
This commit is contained in:
parent
666e475032
commit
7d28d30666
39 changed files with 1670 additions and 209 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue