Skip to content

Commit a1e7584

Browse files
authored
Merge pull request embassy-rs#3797 from stargazing-dino/add-channel-stream
Add stream impl for embassy-sync Channels
2 parents fcee67a + 269dec9 commit a1e7584

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

embassy-sync/src/channel.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,17 @@ where
317317
}
318318
}
319319

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+
320331
/// Future returned by [`Channel::receive`] and [`Receiver::receive`].
321332
#[must_use = "futures do nothing unless you `.await` or poll them"]
322333
pub struct ReceiveFuture<'ch, M, T, const N: usize>
@@ -771,6 +782,17 @@ where
771782
}
772783
}
773784

785+
impl<M, T, const N: usize> futures_util::Stream for Channel<M, T, N>
786+
where
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+
774796
#[cfg(test)]
775797
mod tests {
776798
use core::time::Duration;

0 commit comments

Comments
 (0)