impl<T> PeekableReceiver<T> { pub fn new(receiver: Receiver<T>) -> Self { Self { inner: Arc::new(Mutex::new(receiver)), next_item: None, } } pub async fn peek(&mut self) -> Option<&T> { if self.next_item.is_none() { let mut receiver = self.inner.lock().await; self.next_item = receiver.recv().await; } self.next_item.as_ref() } pub fn advance(&mut self) { self.next_item = None; } pub async fn recv(&mut self) -> Option<T> { if self.next_item.is_none() { let mut receiver = self.inner.lock().await; receiver.recv().await } else { self.next_item.take() } } }