mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 06:42:32 +00:00
Adding ready_to_receive to Channel and Receiver
Adding ReceiveReadyFuture
This commit is contained in:
parent
da86c08651
commit
30dcc88093
@ -152,6 +152,13 @@ where
|
|||||||
self.channel.receive()
|
self.channel.receive()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is a value ready to be received in the channel
|
||||||
|
///
|
||||||
|
/// See [`Channel::ready_to_receive()`].
|
||||||
|
pub fn ready_to_receive(&self) -> ReceiveReadyFuture<'_, M, T, N> {
|
||||||
|
self.channel.ready_to_receive()
|
||||||
|
}
|
||||||
|
|
||||||
/// Attempt to immediately receive the next value.
|
/// Attempt to immediately receive the next value.
|
||||||
///
|
///
|
||||||
/// See [`Channel::try_receive()`]
|
/// See [`Channel::try_receive()`]
|
||||||
@ -246,6 +253,26 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Future returned by [`Channel::ready_to_receive`] and [`Receiver::ready_to_receive`].
|
||||||
|
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
||||||
|
pub struct ReceiveReadyFuture<'ch, M, T, const N: usize>
|
||||||
|
where
|
||||||
|
M: RawMutex,
|
||||||
|
{
|
||||||
|
channel: &'ch Channel<M, T, N>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ch, M, T, const N: usize> Future for ReceiveReadyFuture<'ch, M, T, N>
|
||||||
|
where
|
||||||
|
M: RawMutex,
|
||||||
|
{
|
||||||
|
type Output = ();
|
||||||
|
|
||||||
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
|
||||||
|
self.channel.poll_ready_to_receive(cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Future returned by [`DynamicReceiver::receive`].
|
/// Future returned by [`DynamicReceiver::receive`].
|
||||||
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
||||||
pub struct DynamicReceiveFuture<'ch, T> {
|
pub struct DynamicReceiveFuture<'ch, T> {
|
||||||
@ -577,6 +604,14 @@ where
|
|||||||
ReceiveFuture { channel: self }
|
ReceiveFuture { channel: self }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is a value ready to be received in the channel
|
||||||
|
///
|
||||||
|
/// If there are no messages in the channel's buffer, this method will
|
||||||
|
/// wait until there is at least one
|
||||||
|
pub fn ready_to_receive(&self) -> ReceiveReadyFuture<'_, M, T, N> {
|
||||||
|
ReceiveReadyFuture { channel: self }
|
||||||
|
}
|
||||||
|
|
||||||
/// Attempt to immediately receive a message.
|
/// Attempt to immediately receive a message.
|
||||||
///
|
///
|
||||||
/// This method will either receive a message from the channel immediately or return an error
|
/// This method will either receive a message from the channel immediately or return an error
|
||||||
|
Loading…
Reference in New Issue
Block a user