Merge pull request #4167 from JuliDi/embassy-sync-docs
Clarify docs for signal and watch
This commit is contained in:
commit
6034b17728
@ -6,7 +6,7 @@ use core::task::{Context, Poll, Waker};
|
|||||||
use crate::blocking_mutex::raw::RawMutex;
|
use crate::blocking_mutex::raw::RawMutex;
|
||||||
use crate::blocking_mutex::Mutex;
|
use crate::blocking_mutex::Mutex;
|
||||||
|
|
||||||
/// Single-slot signaling primitive.
|
/// Single-slot signaling primitive for a _single_ consumer.
|
||||||
///
|
///
|
||||||
/// This is similar to a [`Channel`](crate::channel::Channel) with a buffer size of 1, except
|
/// This is similar to a [`Channel`](crate::channel::Channel) with a buffer size of 1, except
|
||||||
/// "sending" to it (calling [`Signal::signal`]) when full will overwrite the previous value instead
|
/// "sending" to it (calling [`Signal::signal`]) when full will overwrite the previous value instead
|
||||||
@ -17,6 +17,7 @@ use crate::blocking_mutex::Mutex;
|
|||||||
/// updates.
|
/// updates.
|
||||||
///
|
///
|
||||||
/// For more advanced use cases, you might want to use [`Channel`](crate::channel::Channel) instead.
|
/// For more advanced use cases, you might want to use [`Channel`](crate::channel::Channel) instead.
|
||||||
|
/// For multiple consumers, use [`Watch`](crate::watch::Watch) instead.
|
||||||
///
|
///
|
||||||
/// Signals are generally declared as `static`s and then borrowed as required.
|
/// Signals are generally declared as `static`s and then borrowed as required.
|
||||||
///
|
///
|
||||||
@ -106,7 +107,7 @@ where
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Future that completes when this Signal has been signaled.
|
/// Future that completes when this Signal has been signaled, taking the value out of the signal.
|
||||||
pub fn wait(&self) -> impl Future<Output = T> + '_ {
|
pub fn wait(&self) -> impl Future<Output = T> + '_ {
|
||||||
poll_fn(move |cx| self.poll_wait(cx))
|
poll_fn(move |cx| self.poll_wait(cx))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use crate::blocking_mutex::raw::RawMutex;
|
|||||||
use crate::blocking_mutex::Mutex;
|
use crate::blocking_mutex::Mutex;
|
||||||
use crate::waitqueue::MultiWakerRegistration;
|
use crate::waitqueue::MultiWakerRegistration;
|
||||||
|
|
||||||
/// The `Watch` is a single-slot signaling primitive that allows multiple receivers to concurrently await
|
/// The `Watch` is a single-slot signaling primitive that allows _multiple_ (`N`) receivers to concurrently await
|
||||||
/// changes to the value. Unlike a [`Signal`](crate::signal::Signal), `Watch` supports multiple receivers,
|
/// changes to the value. Unlike a [`Signal`](crate::signal::Signal), `Watch` supports multiple receivers,
|
||||||
/// and unlike a [`PubSubChannel`](crate::pubsub::PubSubChannel), `Watch` immediately overwrites the previous
|
/// and unlike a [`PubSubChannel`](crate::pubsub::PubSubChannel), `Watch` immediately overwrites the previous
|
||||||
/// value when a new one is sent, without waiting for all receivers to read the previous value.
|
/// 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>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<M: RawMutex, T: Clone, const N: usize> Watch<M, T, N> {
|
impl<M: RawMutex, T: Clone, const N: usize> Watch<M, T, N> {
|
||||||
/// Create a new `Watch` channel.
|
/// Create a new `Watch` channel for `N` receivers.
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
mutex: Mutex::new(RefCell::new(WatchState {
|
mutex: Mutex::new(RefCell::new(WatchState {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user