aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy/src/util/mpsc.rs31
1 files changed, 12 insertions, 19 deletions
diff --git a/embassy/src/util/mpsc.rs b/embassy/src/util/mpsc.rs
index e54c507c1..8f1bba764 100644
--- a/embassy/src/util/mpsc.rs
+++ b/embassy/src/util/mpsc.rs
@@ -141,7 +141,18 @@ where
141 /// 141 ///
142 /// [`close`]: Self::close 142 /// [`close`]: Self::close
143 pub async fn recv(&mut self) -> Option<T> { 143 pub async fn recv(&mut self) -> Option<T> {
144 self.await 144 futures::future::poll_fn(|cx| self.recv_poll(cx)).await
145 }
146
147 fn recv_poll(self: &mut Self, cx: &mut Context<'_>) -> Poll<Option<T>> {
148 match self.try_recv() {
149 Ok(v) => Poll::Ready(Some(v)),
150 Err(TryRecvError::Closed) => Poll::Ready(None),
151 Err(TryRecvError::Empty) => {
152 self.channel.get().set_receiver_waker(cx.waker().clone());
153 Poll::Pending
154 }
155 }
145 } 156 }
146 157
147 /// Attempts to immediately receive a message on this `Receiver` 158 /// Attempts to immediately receive a message on this `Receiver`
@@ -167,24 +178,6 @@ where
167 } 178 }
168} 179}
169 180
170impl<'ch, M, T, const N: usize> Future for Receiver<'ch, M, T, N>
171where
172 M: Mutex<Data = ()>,
173{
174 type Output = Option<T>;
175
176 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
177 match self.try_recv() {
178 Ok(v) => Poll::Ready(Some(v)),
179 Err(TryRecvError::Closed) => Poll::Ready(None),
180 Err(TryRecvError::Empty) => {
181 self.channel.get().set_receiver_waker(cx.waker().clone());
182 Poll::Pending
183 }
184 }
185 }
186}
187
188impl<'ch, M, T, const N: usize> Drop for Receiver<'ch, M, T, N> 181impl<'ch, M, T, const N: usize> Drop for Receiver<'ch, M, T, N>
189where 182where
190 M: Mutex<Data = ()>, 183 M: Mutex<Data = ()>,