diff options
| author | Rex Magana <[email protected]> | 2025-01-22 11:26:08 -0700 |
|---|---|---|
| committer | Rex Magana <[email protected]> | 2025-01-22 11:26:08 -0700 |
| commit | 269dec938015c387d419afebb8402f5bee633ca9 (patch) | |
| tree | 941285d41f14d93efd1c5f6e476f8524f946f9b8 | |
| parent | 195b1a593a4f51ebc7ae61b5045c620a1dbd25d8 (diff) | |
add stream impl
| -rw-r--r-- | embassy-sync/src/channel.rs | 22 |
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 | ||
| 320 | impl<'ch, M, T, const N: usize> futures_util::Stream for Receiver<'ch, M, T, N> | ||
| 321 | where | ||
| 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"] |
| 322 | pub struct ReceiveFuture<'ch, M, T, const N: usize> | 333 | pub struct ReceiveFuture<'ch, M, T, const N: usize> |
| @@ -768,6 +779,17 @@ where | |||
| 768 | } | 779 | } |
| 769 | } | 780 | } |
| 770 | 781 | ||
| 782 | impl<M, T, const N: usize> futures_util::Stream for Channel<M, T, N> | ||
| 783 | where | ||
| 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)] |
| 772 | mod tests { | 794 | mod tests { |
| 773 | use core::time::Duration; | 795 | use core::time::Duration; |
