Merge pull request #3521 from Gibbz/main

embassy_sync::watch default values
This commit is contained in:
Ulf Lilleengen 2024-11-10 13:34:44 +00:00 committed by GitHub
commit d6a8dce6ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -310,6 +310,18 @@ impl<M: RawMutex, T: Clone, const N: usize> Watch<M, T, N> {
} }
} }
/// Create a new `Watch` channel with default data.
pub const fn new_with(data: T) -> Self {
Self {
mutex: Mutex::new(RefCell::new(WatchState {
data: Some(data),
current_id: 0,
wakers: MultiWakerRegistration::new(),
receiver_count: 0,
})),
}
}
/// Create a new [`Sender`] for the `Watch`. /// Create a new [`Sender`] for the `Watch`.
pub fn sender(&self) -> Sender<'_, M, T, N> { pub fn sender(&self) -> Sender<'_, M, T, N> {
Sender(Snd::new(self)) Sender(Snd::new(self))