diff options
| author | JuliDi <[email protected]> | 2025-05-04 16:31:26 +0200 |
|---|---|---|
| committer | JuliDi <[email protected]> | 2025-05-04 16:31:26 +0200 |
| commit | 723ebfcb4f17e48f2a614f0e1e124e8da9c75b70 (patch) | |
| tree | 170a6493e95fc2adb7c8bed3e151a1f421234272 | |
| parent | 9fee43f2bd57e7ce77321d001cdd287f0bd6fef2 (diff) | |
clarify docs for signal and watch
| -rw-r--r-- | embassy-sync/src/signal.rs | 5 | ||||
| -rw-r--r-- | embassy-sync/src/watch.rs | 4 |
2 files changed, 5 insertions, 4 deletions
diff --git a/embassy-sync/src/signal.rs b/embassy-sync/src/signal.rs index a0f4b5a74..e7095401e 100644 --- a/embassy-sync/src/signal.rs +++ b/embassy-sync/src/signal.rs | |||
| @@ -6,7 +6,7 @@ use core::task::{Context, Poll, Waker}; | |||
| 6 | use crate::blocking_mutex::raw::RawMutex; | 6 | use crate::blocking_mutex::raw::RawMutex; |
| 7 | use crate::blocking_mutex::Mutex; | 7 | use crate::blocking_mutex::Mutex; |
| 8 | 8 | ||
| 9 | /// Single-slot signaling primitive. | 9 | /// Single-slot signaling primitive for a _single_ consumer. |
| 10 | /// | 10 | /// |
| 11 | /// This is similar to a [`Channel`](crate::channel::Channel) with a buffer size of 1, except | 11 | /// This is similar to a [`Channel`](crate::channel::Channel) with a buffer size of 1, except |
| 12 | /// "sending" to it (calling [`Signal::signal`]) when full will overwrite the previous value instead | 12 | /// "sending" to it (calling [`Signal::signal`]) when full will overwrite the previous value instead |
| @@ -17,6 +17,7 @@ use crate::blocking_mutex::Mutex; | |||
| 17 | /// updates. | 17 | /// updates. |
| 18 | /// | 18 | /// |
| 19 | /// For more advanced use cases, you might want to use [`Channel`](crate::channel::Channel) instead. | 19 | /// For more advanced use cases, you might want to use [`Channel`](crate::channel::Channel) instead. |
| 20 | /// For multiple consumers, use [`Watch`](crate::watch::Watch) instead. | ||
| 20 | /// | 21 | /// |
| 21 | /// Signals are generally declared as `static`s and then borrowed as required. | 22 | /// Signals are generally declared as `static`s and then borrowed as required. |
| 22 | /// | 23 | /// |
| @@ -106,7 +107,7 @@ where | |||
| 106 | }) | 107 | }) |
| 107 | } | 108 | } |
| 108 | 109 | ||
| 109 | /// Future that completes when this Signal has been signaled. | 110 | /// Future that completes when this Signal has been signaled, taking the value out of the signal. |
| 110 | pub fn wait(&self) -> impl Future<Output = T> + '_ { | 111 | pub fn wait(&self) -> impl Future<Output = T> + '_ { |
| 111 | poll_fn(move |cx| self.poll_wait(cx)) | 112 | poll_fn(move |cx| self.poll_wait(cx)) |
| 112 | } | 113 | } |
diff --git a/embassy-sync/src/watch.rs b/embassy-sync/src/watch.rs index e76646c0b..08d6a833d 100644 --- a/embassy-sync/src/watch.rs +++ b/embassy-sync/src/watch.rs | |||
| @@ -10,7 +10,7 @@ use crate::blocking_mutex::raw::RawMutex; | |||
| 10 | use crate::blocking_mutex::Mutex; | 10 | use crate::blocking_mutex::Mutex; |
| 11 | use crate::waitqueue::MultiWakerRegistration; | 11 | use crate::waitqueue::MultiWakerRegistration; |
| 12 | 12 | ||
| 13 | /// The `Watch` is a single-slot signaling primitive that allows multiple receivers to concurrently await | 13 | /// The `Watch` is a single-slot signaling primitive that allows _multiple_ (`N`) receivers to concurrently await |
| 14 | /// changes to the value. Unlike a [`Signal`](crate::signal::Signal), `Watch` supports multiple receivers, | 14 | /// changes to the value. Unlike a [`Signal`](crate::signal::Signal), `Watch` supports multiple receivers, |
| 15 | /// and unlike a [`PubSubChannel`](crate::pubsub::PubSubChannel), `Watch` immediately overwrites the previous | 15 | /// and unlike a [`PubSubChannel`](crate::pubsub::PubSubChannel), `Watch` immediately overwrites the previous |
| 16 | /// value when a new one is sent, without waiting for all receivers to read the previous value. | 16 | /// value when a new one is sent, without waiting for all receivers to read the previous value. |
| @@ -298,7 +298,7 @@ impl<M: RawMutex, T: Clone, const N: usize> WatchBehavior<T> for Watch<M, T, N> | |||
| 298 | } | 298 | } |
| 299 | 299 | ||
| 300 | impl<M: RawMutex, T: Clone, const N: usize> Watch<M, T, N> { | 300 | impl<M: RawMutex, T: Clone, const N: usize> Watch<M, T, N> { |
| 301 | /// Create a new `Watch` channel. | 301 | /// Create a new `Watch` channel for `N` receivers. |
| 302 | pub const fn new() -> Self { | 302 | pub const fn new() -> Self { |
| 303 | Self { | 303 | Self { |
| 304 | mutex: Mutex::new(RefCell::new(WatchState { | 304 | mutex: Mutex::new(RefCell::new(WatchState { |
