diff options
| author | Ruben De Smet <[email protected]> | 2023-08-11 11:58:22 +0200 |
|---|---|---|
| committer | Ruben De Smet <[email protected]> | 2023-08-22 16:58:31 +0200 |
| commit | c39671266e21dd9e35e60cc680453cd5c38162db (patch) | |
| tree | 895dbbcefb90af1fd65c8844c1e5785a909b0671 /embassy-sync | |
| parent | b1ec460b9af131ef80fcafd79a7f63aa326aaf94 (diff) | |
Deprecate *recv* in favor of *receive*
Diffstat (limited to 'embassy-sync')
| -rw-r--r-- | embassy-sync/src/channel.rs | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs index dc727fb10..62ea1307d 100644 --- a/embassy-sync/src/channel.rs +++ b/embassy-sync/src/channel.rs | |||
| @@ -147,16 +147,16 @@ where | |||
| 147 | { | 147 | { |
| 148 | /// Receive the next value. | 148 | /// Receive the next value. |
| 149 | /// | 149 | /// |
| 150 | /// See [`Channel::recv()`]. | 150 | /// See [`Channel::receive()`]. |
| 151 | pub fn recv(&self) -> RecvFuture<'_, M, T, N> { | 151 | pub fn receive(&self) -> ReceiveFuture<'_, M, T, N> { |
| 152 | self.channel.recv() | 152 | self.channel.receive() |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | /// Attempt to immediately receive the next value. | 155 | /// Attempt to immediately receive the next value. |
| 156 | /// | 156 | /// |
| 157 | /// See [`Channel::try_recv()`] | 157 | /// See [`Channel::try_receive()`] |
| 158 | pub fn try_recv(&self) -> Result<T, TryRecvError> { | 158 | pub fn try_receive(&self) -> Result<T, TryReceiveError> { |
| 159 | self.channel.try_recv() | 159 | self.channel.try_receive() |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 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 |
| @@ -190,16 +190,16 @@ impl<'ch, T> Copy for DynamicReceiver<'ch, T> {} | |||
| 190 | impl<'ch, T> DynamicReceiver<'ch, T> { | 190 | impl<'ch, T> DynamicReceiver<'ch, T> { |
| 191 | /// Receive the next value. | 191 | /// Receive the next value. |
| 192 | /// | 192 | /// |
| 193 | /// See [`Channel::recv()`]. | 193 | /// See [`Channel::receive()`]. |
| 194 | pub fn recv(&self) -> DynamicRecvFuture<'_, T> { | 194 | pub fn receive(&self) -> DynamicReceiveFuture<'_, T> { |
| 195 | DynamicRecvFuture { channel: self.channel } | 195 | DynamicReceiveFuture { channel: self.channel } |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | /// Attempt to immediately receive the next value. | 198 | /// Attempt to immediately receive the next value. |
| 199 | /// | 199 | /// |
| 200 | /// See [`Channel::try_recv()`] | 200 | /// See [`Channel::try_receive()`] |
| 201 | pub fn try_recv(&self) -> Result<T, TryRecvError> { | 201 | pub fn try_receive(&self) -> Result<T, TryReceiveError> { |
| 202 | self.channel.try_recv_with_context(None) | 202 | self.channel.try_receive_with_context(None) |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | /// Allows a poll_fn to poll until the channel is ready to receive | 205 | /// Allows a poll_fn to poll until the channel is ready to receive |
| @@ -226,16 +226,16 @@ where | |||
| 226 | } | 226 | } |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | /// Future returned by [`Channel::recv`] and [`Receiver::recv`]. | 229 | /// Future returned by [`Channel::receive`] and [`Receiver::receive`]. |
| 230 | #[must_use = "futures do nothing unless you `.await` or poll them"] | 230 | #[must_use = "futures do nothing unless you `.await` or poll them"] |
| 231 | pub struct RecvFuture<'ch, M, T, const N: usize> | 231 | pub struct ReceiveFuture<'ch, M, T, const N: usize> |
| 232 | where | 232 | where |
| 233 | M: RawMutex, | 233 | M: RawMutex, |
| 234 | { | 234 | { |
| 235 | channel: &'ch Channel<M, T, N>, | 235 | channel: &'ch Channel<M, T, N>, |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | impl<'ch, M, T, const N: usize> Future for RecvFuture<'ch, M, T, N> | 238 | impl<'ch, M, T, const N: usize> Future for ReceiveFuture<'ch, M, T, N> |
| 239 | where | 239 | where |
| 240 | M: RawMutex, | 240 | M: RawMutex, |
| 241 | { | 241 | { |
| @@ -246,19 +246,19 @@ where | |||
| 246 | } | 246 | } |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | /// Future returned by [`DynamicReceiver::recv`]. | 249 | /// Future returned by [`DynamicReceiver::receive`]. |
| 250 | #[must_use = "futures do nothing unless you `.await` or poll them"] | 250 | #[must_use = "futures do nothing unless you `.await` or poll them"] |
| 251 | pub struct DynamicRecvFuture<'ch, T> { | 251 | pub struct DynamicReceiveFuture<'ch, T> { |
| 252 | channel: &'ch dyn DynamicChannel<T>, | 252 | channel: &'ch dyn DynamicChannel<T>, |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | impl<'ch, T> Future for DynamicRecvFuture<'ch, T> { | 255 | impl<'ch, T> Future for DynamicReceiveFuture<'ch, T> { |
| 256 | type Output = T; | 256 | type Output = T; |
| 257 | 257 | ||
| 258 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { | 258 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { |
| 259 | match self.channel.try_recv_with_context(Some(cx)) { | 259 | match self.channel.try_receive_with_context(Some(cx)) { |
| 260 | Ok(v) => Poll::Ready(v), | 260 | Ok(v) => Poll::Ready(v), |
| 261 | Err(TryRecvError::Empty) => Poll::Pending, | 261 | Err(TryReceiveError::Empty) => Poll::Pending, |
| 262 | } | 262 | } |
| 263 | } | 263 | } |
| 264 | } | 264 | } |
| @@ -324,7 +324,7 @@ impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {} | |||
| 324 | trait DynamicChannel<T> { | 324 | trait DynamicChannel<T> { |
| 325 | fn try_send_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>>; | 325 | fn try_send_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>>; |
| 326 | 326 | ||
| 327 | fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError>; | 327 | fn try_receive_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryReceiveError>; |
| 328 | 328 | ||
| 329 | fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()>; | 329 | fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()>; |
| 330 | fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()>; | 330 | fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()>; |
| @@ -332,10 +332,10 @@ trait DynamicChannel<T> { | |||
| 332 | fn poll_receive(&self, cx: &mut Context<'_>) -> Poll<T>; | 332 | fn poll_receive(&self, cx: &mut Context<'_>) -> Poll<T>; |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | /// Error returned by [`try_recv`](Channel::try_recv). | 335 | /// Error returned by [`try_receive`](Channel::try_receive). |
| 336 | #[derive(PartialEq, Eq, Clone, Copy, Debug)] | 336 | #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
| 337 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 337 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 338 | pub enum TryRecvError { | 338 | pub enum TryReceiveError { |
| 339 | /// A message could not be received because the channel is empty. | 339 | /// A message could not be received because the channel is empty. |
| 340 | Empty, | 340 | Empty, |
| 341 | } | 341 | } |
| @@ -364,11 +364,11 @@ impl<T, const N: usize> ChannelState<T, N> { | |||
| 364 | } | 364 | } |
| 365 | } | 365 | } |
| 366 | 366 | ||
| 367 | fn try_recv(&mut self) -> Result<T, TryRecvError> { | 367 | fn try_receive(&mut self) -> Result<T, TryReceiveError> { |
| 368 | self.try_recv_with_context(None) | 368 | self.try_receive_with_context(None) |
| 369 | } | 369 | } |
| 370 | 370 | ||
| 371 | fn try_recv_with_context(&mut self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError> { | 371 | fn try_receive_with_context(&mut self, cx: Option<&mut Context<'_>>) -> Result<T, TryReceiveError> { |
| 372 | if self.queue.is_full() { | 372 | if self.queue.is_full() { |
| 373 | self.senders_waker.wake(); | 373 | self.senders_waker.wake(); |
| 374 | } | 374 | } |
| @@ -379,7 +379,7 @@ impl<T, const N: usize> ChannelState<T, N> { | |||
| 379 | if let Some(cx) = cx { | 379 | if let Some(cx) = cx { |
| 380 | self.receiver_waker.register(cx.waker()); | 380 | self.receiver_waker.register(cx.waker()); |
| 381 | } | 381 | } |
| 382 | Err(TryRecvError::Empty) | 382 | Err(TryReceiveError::Empty) |
| 383 | } | 383 | } |
| 384 | } | 384 | } |
| 385 | 385 | ||
| @@ -474,8 +474,8 @@ where | |||
| 474 | self.inner.lock(|rc| f(&mut *rc.borrow_mut())) | 474 | self.inner.lock(|rc| f(&mut *rc.borrow_mut())) |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 477 | fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError> { | 477 | fn try_receive_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryReceiveError> { |
| 478 | self.lock(|c| c.try_recv_with_context(cx)) | 478 | self.lock(|c| c.try_receive_with_context(cx)) |
| 479 | } | 479 | } |
| 480 | 480 | ||
| 481 | /// Poll the channel for the next message | 481 | /// Poll the channel for the next message |
| @@ -536,16 +536,16 @@ where | |||
| 536 | /// | 536 | /// |
| 537 | /// If there are no messages in the channel's buffer, this method will | 537 | /// If there are no messages in the channel's buffer, this method will |
| 538 | /// wait until a message is sent. | 538 | /// wait until a message is sent. |
| 539 | pub fn recv(&self) -> RecvFuture<'_, M, T, N> { | 539 | pub fn receive(&self) -> ReceiveFuture<'_, M, T, N> { |
| 540 | RecvFuture { channel: self } | 540 | ReceiveFuture { channel: self } |
| 541 | } | 541 | } |
| 542 | 542 | ||
| 543 | /// Attempt to immediately receive a message. | 543 | /// Attempt to immediately receive a message. |
| 544 | /// | 544 | /// |
| 545 | /// This method will either receive a message from the channel immediately or return an error | 545 | /// This method will either receive a message from the channel immediately or return an error |
| 546 | /// if the channel is empty. | 546 | /// if the channel is empty. |
| 547 | pub fn try_recv(&self) -> Result<T, TryRecvError> { | 547 | pub fn try_receive(&self) -> Result<T, TryReceiveError> { |
| 548 | self.lock(|c| c.try_recv()) | 548 | self.lock(|c| c.try_receive()) |
| 549 | } | 549 | } |
| 550 | } | 550 | } |
| 551 | 551 | ||
| @@ -559,8 +559,8 @@ where | |||
| 559 | Channel::try_send_with_context(self, m, cx) | 559 | Channel::try_send_with_context(self, m, cx) |
| 560 | } | 560 | } |
| 561 | 561 | ||
| 562 | fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError> { | 562 | fn try_receive_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryReceiveError> { |
| 563 | Channel::try_recv_with_context(self, cx) | 563 | Channel::try_receive_with_context(self, cx) |
| 564 | } | 564 | } |
| 565 | 565 | ||
| 566 | fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> { | 566 | fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> { |
| @@ -616,15 +616,15 @@ mod tests { | |||
| 616 | fn receiving_once_with_one_send() { | 616 | fn receiving_once_with_one_send() { |
| 617 | let mut c = ChannelState::<u32, 3>::new(); | 617 | let mut c = ChannelState::<u32, 3>::new(); |
| 618 | assert!(c.try_send(1).is_ok()); | 618 | assert!(c.try_send(1).is_ok()); |
| 619 | assert_eq!(c.try_recv().unwrap(), 1); | 619 | assert_eq!(c.try_receive().unwrap(), 1); |
| 620 | assert_eq!(capacity(&c), 3); | 620 | assert_eq!(capacity(&c), 3); |
| 621 | } | 621 | } |
| 622 | 622 | ||
| 623 | #[test] | 623 | #[test] |
| 624 | fn receiving_when_empty() { | 624 | fn receiving_when_empty() { |
| 625 | let mut c = ChannelState::<u32, 3>::new(); | 625 | let mut c = ChannelState::<u32, 3>::new(); |
| 626 | match c.try_recv() { | 626 | match c.try_receive() { |
| 627 | Err(TryRecvError::Empty) => assert!(true), | 627 | Err(TryReceiveError::Empty) => assert!(true), |
| 628 | _ => assert!(false), | 628 | _ => assert!(false), |
| 629 | } | 629 | } |
| 630 | assert_eq!(capacity(&c), 3); | 630 | assert_eq!(capacity(&c), 3); |
| @@ -634,7 +634,7 @@ mod tests { | |||
| 634 | fn simple_send_and_receive() { | 634 | fn simple_send_and_receive() { |
| 635 | let c = Channel::<NoopRawMutex, u32, 3>::new(); | 635 | let c = Channel::<NoopRawMutex, u32, 3>::new(); |
| 636 | assert!(c.try_send(1).is_ok()); | 636 | assert!(c.try_send(1).is_ok()); |
| 637 | assert_eq!(c.try_recv().unwrap(), 1); | 637 | assert_eq!(c.try_receive().unwrap(), 1); |
| 638 | } | 638 | } |
| 639 | 639 | ||
| 640 | #[test] | 640 | #[test] |
| @@ -654,7 +654,7 @@ mod tests { | |||
| 654 | let r: DynamicReceiver<'_, u32> = c.receiver().into(); | 654 | let r: DynamicReceiver<'_, u32> = c.receiver().into(); |
| 655 | 655 | ||
| 656 | assert!(s.try_send(1).is_ok()); | 656 | assert!(s.try_send(1).is_ok()); |
| 657 | assert_eq!(r.try_recv().unwrap(), 1); | 657 | assert_eq!(r.try_receive().unwrap(), 1); |
| 658 | } | 658 | } |
| 659 | 659 | ||
| 660 | #[futures_test::test] | 660 | #[futures_test::test] |
| @@ -669,14 +669,14 @@ mod tests { | |||
| 669 | assert!(c2.try_send(1).is_ok()); | 669 | assert!(c2.try_send(1).is_ok()); |
| 670 | }) | 670 | }) |
| 671 | .is_ok()); | 671 | .is_ok()); |
| 672 | assert_eq!(c.recv().await, 1); | 672 | assert_eq!(c.receive().await, 1); |
| 673 | } | 673 | } |
| 674 | 674 | ||
| 675 | #[futures_test::test] | 675 | #[futures_test::test] |
| 676 | async fn sender_send_completes_if_capacity() { | 676 | async fn sender_send_completes_if_capacity() { |
| 677 | let c = Channel::<CriticalSectionRawMutex, u32, 1>::new(); | 677 | let c = Channel::<CriticalSectionRawMutex, u32, 1>::new(); |
| 678 | c.send(1).await; | 678 | c.send(1).await; |
| 679 | assert_eq!(c.recv().await, 1); | 679 | assert_eq!(c.receive().await, 1); |
| 680 | } | 680 | } |
| 681 | 681 | ||
| 682 | #[futures_test::test] | 682 | #[futures_test::test] |
| @@ -694,11 +694,11 @@ mod tests { | |||
| 694 | // Wish I could think of a means of determining that the async send is waiting instead. | 694 | // Wish I could think of a means of determining that the async send is waiting instead. |
| 695 | // However, I've used the debugger to observe that the send does indeed wait. | 695 | // However, I've used the debugger to observe that the send does indeed wait. |
| 696 | Delay::new(Duration::from_millis(500)).await; | 696 | Delay::new(Duration::from_millis(500)).await; |
| 697 | assert_eq!(c.recv().await, 1); | 697 | assert_eq!(c.receive().await, 1); |
| 698 | assert!(executor | 698 | assert!(executor |
| 699 | .spawn(async move { | 699 | .spawn(async move { |
| 700 | loop { | 700 | loop { |
| 701 | c.recv().await; | 701 | c.receive().await; |
| 702 | } | 702 | } |
| 703 | }) | 703 | }) |
| 704 | .is_ok()); | 704 | .is_ok()); |
