Skip to content

Commit 269dec9

Browse files
add stream impl
1 parent 195b1a5 commit 269dec9

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>
@@ -768,6 +779,17 @@ where
768779
}
769780
}
770781

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+
771793
#[cfg(test)]
772794
mod tests {
773795
use core::time::Duration;

0 commit comments

Comments
 (0)