Merge pull request #3797 from stargazing-dino/add-channel-stream

Add stream impl for embassy-sync Channels
This commit is contained in:
Dario Nieuwenhuis 2025-02-19 15:46:45 +01:00 committed by GitHub
commit a1e75841f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -317,6 +317,17 @@ where
}
}
impl<'ch, M, T, const N: usize> futures_util::Stream for Receiver<'ch, M, T, N>
where
M: RawMutex,
{
type Item = T;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.channel.poll_receive(cx).map(Some)
}
}
/// Future returned by [`Channel::receive`] and [`Receiver::receive`].
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct ReceiveFuture<'ch, M, T, const N: usize>
@ -771,6 +782,17 @@ where
}
}
impl<M, T, const N: usize> futures_util::Stream for Channel<M, T, N>
where
M: RawMutex,
{
type Item = T;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.poll_receive(cx).map(Some)
}
}
#[cfg(test)]
mod tests {
use core::time::Duration;