Struct embassy_sync::signal::Signal

source ·
pub struct Signal<M, T>where
    M: RawMutex,{ /* private fields */ }
Expand description

Single-slot signaling primitive.

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.

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,

source

pub const fn new() -> Self

Create a new Signal.

source§

impl<M, T: Send> Signal<M, T>where M: RawMutex,

source

pub fn signal(&self, val: T)

Mark this Signal as signaled.

source

pub fn reset(&self)

Remove the queued value in this Signal, if any.

source

pub fn wait(&self) -> impl Future<Output = T> + '_

Future that completes when this Signal has been signaled.

source

pub fn signaled(&self) -> bool

non-blocking method to check whether this signal has been signaled.

Trait Implementations§

source§

impl<M, T> Default for Signal<M, T>where M: RawMutex,

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<M, T> !RefUnwindSafe for Signal<M, T>

§

impl<M, T> Send for Signal<M, T>where M: Send, T: Send,

§

impl<M, T> Sync for Signal<M, T>where M: Sync, T: Send,

§

impl<M, T> Unpin for Signal<M, T>where M: Unpin, T: Unpin,

§

impl<M, T> UnwindSafe for Signal<M, T>where M: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.