pub struct Signal<M, T>where
M: RawMutex,{ /* private fields */ }Expand description
Single-slot signaling primitive for a single consumer.
This is similar to a Channel with a buffer size of 1, except
“sending” to it (calling Signal::signal) when full will overwrite the previous value instead
of waiting for the receiver to pop the previous value.
It is useful for sending data between tasks when the receiver only cares about the latest data, and therefore it’s fine to “lose” messages. This is often the case for “state” updates.
For more advanced use cases, you might want to use Channel instead.
For multiple consumers, use Watch instead.
Signals are generally declared as statics and then borrowed as required.
use embassy_sync::signal::Signal;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
enum SomeCommand {
On,
Off,
}
static SOME_SIGNAL: Signal<CriticalSectionRawMutex, SomeCommand> = Signal::new();Implementations§
Source§impl<M, T> Signal<M, T>where
M: RawMutex,
impl<M, T> Signal<M, T>where
M: RawMutex,
Sourcepub fn poll_wait(&self, cx: &mut Context<'_>) -> Poll<T>
pub fn poll_wait(&self, cx: &mut Context<'_>) -> Poll<T>
Poll for state changes of this Signal.
Trait Implementations§
Source§impl<M, T> Sink<T> for Signal<M, T>where
M: RawMutex,
impl<M, T> Sink<T> for Signal<M, T>where
M: RawMutex,
Source§fn poll_ready(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Attempts to prepare the
Sink to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>
Begin the process of sending a value to the sink.
Each call to this function must be preceded by a successful call to
poll_ready which returned Poll::Ready(Ok(())). Read moreSource§impl<M, T> Sink<T> for &Signal<M, T>where
M: RawMutex,
impl<M, T> Sink<T> for &Signal<M, T>where
M: RawMutex,
Source§fn poll_ready(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Attempts to prepare the
Sink to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>
Begin the process of sending a value to the sink.
Each call to this function must be preceded by a successful call to
poll_ready which returned Poll::Ready(Ok(())). Read moreSource§impl<M, T> Stream for Signal<M, T>where
M: RawMutex,
impl<M, T> Stream for Signal<M, T>where
M: RawMutex,
Source§impl<M, T> Stream for &Signal<M, T>where
M: RawMutex,
impl<M, T> Stream for &Signal<M, T>where
M: RawMutex,
Auto Trait Implementations§
impl<M, T> !Freeze for Signal<M, T>
impl<M, T> !RefUnwindSafe for Signal<M, T>
impl<M, T> Send for Signal<M, T>
impl<M, T> Sync for Signal<M, T>
impl<M, T> Unpin for Signal<M, T>
impl<M, T> UnsafeUnpin for Signal<M, T>
impl<M, T> UnwindSafe for Signal<M, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more