aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync/src
diff options
context:
space:
mode:
authorRex Magana <[email protected]>2025-01-22 11:26:08 -0700
committerRex Magana <[email protected]>2025-01-22 11:26:08 -0700
commit269dec938015c387d419afebb8402f5bee633ca9 (patch)
tree941285d41f14d93efd1c5f6e476f8524f946f9b8 /embassy-sync/src
parent195b1a593a4f51ebc7ae61b5045c620a1dbd25d8 (diff)
add stream impl
Diffstat (limited to 'embassy-sync/src')
-rw-r--r--embassy-sync/src/channel.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs
index 18b053111..b3b087bf6 100644
--- a/embassy-sync/src/channel.rs
+++ b/embassy-sync/src/channel.rs
@@ -317,6 +317,17 @@ where
317 } 317 }
318} 318}
319 319
320impl<'ch, M, T, const N: usize> futures_util::Stream for Receiver<'ch, M, T, N>
321where
322 M: RawMutex,
323{
324 type Item = T;
325
326 fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
327 self.channel.poll_receive(cx).map(Some)
328 }
329}
330
320/// Future returned by [`Channel::receive`] and [`Receiver::receive`]. 331/// Future returned by [`Channel::receive`] and [`Receiver::receive`].
321#[must_use = "futures do nothing unless you `.await` or poll them"] 332#[must_use = "futures do nothing unless you `.await` or poll them"]
322pub struct ReceiveFuture<'ch, M, T, const N: usize> 333pub struct ReceiveFuture<'ch, M, T, const N: usize>
@@ -768,6 +779,17 @@ where
768 } 779 }
769} 780}
770 781
782impl<M, T, const N: usize> futures_util::Stream for Channel<M, T, N>
783where
784 M: RawMutex,
785{
786 type Item = T;
787
788 fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
789 self.poll_receive(cx).map(Some)
790 }
791}
792
771#[cfg(test)] 793#[cfg(test)]
772mod tests { 794mod tests {
773 use core::time::Duration; 795 use core::time::Duration;