aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-02-19 15:46:45 +0100
committerGitHub <[email protected]>2025-02-19 15:46:45 +0100
commita1e75841f8940153ef8e0fdb38d6c8ba7322edb9 (patch)
tree0334bc20afa285fc2b7e0767890af594a39e6350 /embassy-sync
parentfcee67a0d2e561a60a9b97df6d06fca02323efee (diff)
parent269dec938015c387d419afebb8402f5bee633ca9 (diff)
Merge pull request #3797 from stargazing-dino/add-channel-stream
Add stream impl for embassy-sync Channels
Diffstat (limited to 'embassy-sync')
-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 9a7d2fa2f..4d1fa9e39 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>
@@ -771,6 +782,17 @@ where
771 } 782 }
772} 783}
773 784
785impl<M, T, const N: usize> futures_util::Stream for Channel<M, T, N>
786where
787 M: RawMutex,
788{
789 type Item = T;
790
791 fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
792 self.poll_receive(cx).map(Some)
793 }
794}
795
774#[cfg(test)] 796#[cfg(test)]
775mod tests { 797mod tests {
776 use core::time::Duration; 798 use core::time::Duration;