mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-26 20:00:27 +00:00
Merge pull request #3797 from stargazing-dino/add-channel-stream
Add stream impl for embassy-sync Channels
This commit is contained in:
commit
a1e75841f8
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user