pub struct Sender<T, const N: usize> { /* private fields */ }Expand description
The sender of the channel.
This is a the main channel component, as this is stored in static memory,
The Sender is the owner of the memory.
You can use it from multiple locations by storing it in a static variable.
static_mem doesn’t have something like channel function,
Because, we don’t have heap to store the Sender and give you an Arc
to clone it. So, the user has to create the receiver from the sender manually.
Use new_receiver to create a receiver.
It will start from the same point as the sender.
Broadcast messages sent by using the send method.
§Examples
use blinkcast::static_mem::Sender;
let sender = Sender::<i32, 4>::new();
let mut receiver = sender.new_receiver();
sender.send(1);
sender.send(2);
assert_eq!(receiver.recv(), Some(1));
assert_eq!(receiver.recv(), Some(2));
assert_eq!(receiver.recv(), None);Implementations§
Source§impl<T: Clone, const N: usize> Sender<T, N>
impl<T: Clone, const N: usize> Sender<T, N>
Sourcepub fn send(&self, value: T)
pub fn send(&self, value: T)
Sends a message to the channel. If the channel is full, the oldest message will be overwritten. So the receiver must be quick or it will lose the old data.
Sourcepub fn new_receiver(&self) -> Receiver<'_, T, N>
pub fn new_receiver(&self) -> Receiver<'_, T, N>
Creates a new receiver that starts from the same point as the sender.
§Examples
use blinkcast::static_mem::Sender;
let sender = Sender::<i32, 4>::new();
sender.send(1);
let mut receiver = sender.new_receiver();
assert_eq!(receiver.recv(), None);
sender.send(2);
assert_eq!(receiver.recv(), Some(2));
assert_eq!(receiver.recv(), None);