aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-sync')
-rw-r--r--embassy-sync/src/channel.rs36
1 files changed, 22 insertions, 14 deletions
diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs
index 3896f70ac..e7224856c 100644
--- a/embassy-sync/src/channel.rs
+++ b/embassy-sync/src/channel.rs
@@ -69,7 +69,7 @@ where
69 /// Allows a poll_fn to poll until the channel is ready to send 69 /// Allows a poll_fn to poll until the channel is ready to send
70 /// 70 ///
71 /// See [`Channel::poll_ready_to_send()`] 71 /// See [`Channel::poll_ready_to_send()`]
72 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool { 72 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
73 self.channel.poll_ready_to_send(cx) 73 self.channel.poll_ready_to_send(cx)
74 } 74 }
75} 75}
@@ -117,7 +117,7 @@ impl<'ch, T> DynamicSender<'ch, T> {
117 /// Allows a poll_fn to poll until the channel is ready to send 117 /// Allows a poll_fn to poll until the channel is ready to send
118 /// 118 ///
119 /// See [`Channel::poll_ready_to_send()`] 119 /// See [`Channel::poll_ready_to_send()`]
120 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool { 120 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
121 self.channel.poll_ready_to_send(cx) 121 self.channel.poll_ready_to_send(cx)
122 } 122 }
123} 123}
@@ -162,7 +162,7 @@ where
162 /// Allows a poll_fn to poll until the channel is ready to receive 162 /// Allows a poll_fn to poll until the channel is ready to receive
163 /// 163 ///
164 /// See [`Channel::poll_ready_to_receive()`] 164 /// See [`Channel::poll_ready_to_receive()`]
165 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool { 165 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()> {
166 self.channel.poll_ready_to_receive(cx) 166 self.channel.poll_ready_to_receive(cx)
167 } 167 }
168} 168}
@@ -198,7 +198,7 @@ impl<'ch, T> DynamicReceiver<'ch, T> {
198 /// Allows a poll_fn to poll until the channel is ready to receive 198 /// Allows a poll_fn to poll until the channel is ready to receive
199 /// 199 ///
200 /// See [`Channel::poll_ready_to_receive()`] 200 /// See [`Channel::poll_ready_to_receive()`]
201 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool { 201 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()> {
202 self.channel.poll_ready_to_receive(cx) 202 self.channel.poll_ready_to_receive(cx)
203 } 203 }
204} 204}
@@ -315,8 +315,8 @@ trait DynamicChannel<T> {
315 315
316 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 317
318 fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool; 318 fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()>;
319 fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool; 319 fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()>;
320} 320}
321 321
322/// Error returned by [`try_recv`](Channel::try_recv). 322/// Error returned by [`try_recv`](Channel::try_recv).
@@ -370,10 +370,14 @@ impl<T, const N: usize> ChannelState<T, N> {
370 } 370 }
371 } 371 }
372 372
373 fn poll_ready_to_receive(&mut self, cx: &mut Context<'_>) -> bool { 373 fn poll_ready_to_receive(&mut self, cx: &mut Context<'_>) -> Poll<()> {
374 self.receiver_waker.register(cx.waker()); 374 self.receiver_waker.register(cx.waker());
375 375
376 !self.queue.is_empty() 376 if !self.queue.is_empty() {
377 Poll::Ready(())
378 } else {
379 Poll::Pending
380 }
377 } 381 }
378 382
379 fn try_send(&mut self, message: T) -> Result<(), TrySendError<T>> { 383 fn try_send(&mut self, message: T) -> Result<(), TrySendError<T>> {
@@ -395,10 +399,14 @@ impl<T, const N: usize> ChannelState<T, N> {
395 } 399 }
396 } 400 }
397 401
398 fn poll_ready_to_send(&mut self, cx: &mut Context<'_>) -> bool { 402 fn poll_ready_to_send(&mut self, cx: &mut Context<'_>) -> Poll<()> {
399 self.senders_waker.register(cx.waker()); 403 self.senders_waker.register(cx.waker());
400 404
401 !self.queue.is_full() 405 if !self.queue.is_full() {
406 Poll::Ready(())
407 } else {
408 Poll::Pending
409 }
402 } 410 }
403} 411}
404 412
@@ -449,12 +457,12 @@ where
449 } 457 }
450 458
451 /// Allows a poll_fn to poll until the channel is ready to receive 459 /// Allows a poll_fn to poll until the channel is ready to receive
452 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool { 460 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()> {
453 self.lock(|c| c.poll_ready_to_receive(cx)) 461 self.lock(|c| c.poll_ready_to_receive(cx))
454 } 462 }
455 463
456 /// Allows a poll_fn to poll until the channel is ready to send 464 /// Allows a poll_fn to poll until the channel is ready to send
457 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool { 465 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
458 self.lock(|c| c.poll_ready_to_send(cx)) 466 self.lock(|c| c.poll_ready_to_send(cx))
459 } 467 }
460 468
@@ -524,11 +532,11 @@ where
524 Channel::try_recv_with_context(self, cx) 532 Channel::try_recv_with_context(self, cx)
525 } 533 }
526 534
527 fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool { 535 fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
528 Channel::poll_ready_to_send(self, cx) 536 Channel::poll_ready_to_send(self, cx)
529 } 537 }
530 538
531 fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool { 539 fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()> {
532 Channel::poll_ready_to_receive(self, cx) 540 Channel::poll_ready_to_receive(self, cx)
533 } 541 }
534} 542}