aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync
diff options
context:
space:
mode:
authorRuben De Smet <[email protected]>2023-08-09 11:50:26 +0200
committerRuben De Smet <[email protected]>2023-08-11 12:13:42 +0200
commitb658f10db9a963d85b8465759692b0aa7973a1d1 (patch)
treeef111c6a786107ea721e2cfb5f02836d22f91989 /embassy-sync
parentc1da2c0219667085124c47d8059ffbf077adaf9d (diff)
Expose poll_ready_to_{send,receive} in Sender/Receiver
Diffstat (limited to 'embassy-sync')
-rw-r--r--embassy-sync/src/channel.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs
index d6f36f53d..3896f70ac 100644
--- a/embassy-sync/src/channel.rs
+++ b/embassy-sync/src/channel.rs
@@ -65,6 +65,13 @@ where
65 pub fn try_send(&self, message: T) -> Result<(), TrySendError<T>> { 65 pub fn try_send(&self, message: T) -> Result<(), TrySendError<T>> {
66 self.channel.try_send(message) 66 self.channel.try_send(message)
67 } 67 }
68
69 /// Allows a poll_fn to poll until the channel is ready to send
70 ///
71 /// See [`Channel::poll_ready_to_send()`]
72 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool {
73 self.channel.poll_ready_to_send(cx)
74 }
68} 75}
69 76
70/// Send-only access to a [`Channel`] without knowing channel size. 77/// Send-only access to a [`Channel`] without knowing channel size.
@@ -106,6 +113,13 @@ impl<'ch, T> DynamicSender<'ch, T> {
106 pub fn try_send(&self, message: T) -> Result<(), TrySendError<T>> { 113 pub fn try_send(&self, message: T) -> Result<(), TrySendError<T>> {
107 self.channel.try_send_with_context(message, None) 114 self.channel.try_send_with_context(message, None)
108 } 115 }
116
117 /// Allows a poll_fn to poll until the channel is ready to send
118 ///
119 /// See [`Channel::poll_ready_to_send()`]
120 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool {
121 self.channel.poll_ready_to_send(cx)
122 }
109} 123}
110 124
111/// Receive-only access to a [`Channel`]. 125/// Receive-only access to a [`Channel`].
@@ -144,6 +158,13 @@ where
144 pub fn try_recv(&self) -> Result<T, TryRecvError> { 158 pub fn try_recv(&self) -> Result<T, TryRecvError> {
145 self.channel.try_recv() 159 self.channel.try_recv()
146 } 160 }
161
162 /// Allows a poll_fn to poll until the channel is ready to receive
163 ///
164 /// See [`Channel::poll_ready_to_receive()`]
165 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool {
166 self.channel.poll_ready_to_receive(cx)
167 }
147} 168}
148 169
149/// Receive-only access to a [`Channel`] without knowing channel size. 170/// Receive-only access to a [`Channel`] without knowing channel size.
@@ -173,6 +194,13 @@ impl<'ch, T> DynamicReceiver<'ch, T> {
173 pub fn try_recv(&self) -> Result<T, TryRecvError> { 194 pub fn try_recv(&self) -> Result<T, TryRecvError> {
174 self.channel.try_recv_with_context(None) 195 self.channel.try_recv_with_context(None)
175 } 196 }
197
198 /// Allows a poll_fn to poll until the channel is ready to receive
199 ///
200 /// See [`Channel::poll_ready_to_receive()`]
201 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool {
202 self.channel.poll_ready_to_receive(cx)
203 }
176} 204}
177 205
178impl<'ch, M, T, const N: usize> From<Receiver<'ch, M, T, N>> for DynamicReceiver<'ch, T> 206impl<'ch, M, T, const N: usize> From<Receiver<'ch, M, T, N>> for DynamicReceiver<'ch, T>
@@ -286,6 +314,9 @@ trait DynamicChannel<T> {
286 fn try_send_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>>; 314 fn try_send_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>>;
287 315
288 fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError>; 316 fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError>;
317
318 fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool;
319 fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool;
289} 320}
290 321
291/// Error returned by [`try_recv`](Channel::try_recv). 322/// Error returned by [`try_recv`](Channel::try_recv).
@@ -492,6 +523,14 @@ where
492 fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError> { 523 fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError> {
493 Channel::try_recv_with_context(self, cx) 524 Channel::try_recv_with_context(self, cx)
494 } 525 }
526
527 fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool {
528 Channel::poll_ready_to_send(self, cx)
529 }
530
531 fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool {
532 Channel::poll_ready_to_receive(self, cx)
533 }
495} 534}
496 535
497#[cfg(test)] 536#[cfg(test)]