aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2024-11-10 13:34:44 +0000
committerGitHub <[email protected]>2024-11-10 13:34:44 +0000
commitd6a8dce6eef22564160bf25b20528b8b78ec63b8 (patch)
treeb4f704b09526fdb7207a09a1085adf1c0772f5dd
parentdc9fc73704b5fc18e9f34a2fc94c06bbe691732a (diff)
parent730dde9ba901d89040d3d943cf36b4217ac52bf9 (diff)
Merge pull request #3521 from Gibbz/main
embassy_sync::watch default values
-rw-r--r--embassy-sync/src/watch.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/embassy-sync/src/watch.rs b/embassy-sync/src/watch.rs
index 59798d04f..404e31714 100644
--- a/embassy-sync/src/watch.rs
+++ b/embassy-sync/src/watch.rs
@@ -310,6 +310,18 @@ impl<M: RawMutex, T: Clone, const N: usize> Watch<M, T, N> {
310 } 310 }
311 } 311 }
312 312
313 /// Create a new `Watch` channel with default data.
314 pub const fn new_with(data: T) -> Self {
315 Self {
316 mutex: Mutex::new(RefCell::new(WatchState {
317 data: Some(data),
318 current_id: 0,
319 wakers: MultiWakerRegistration::new(),
320 receiver_count: 0,
321 })),
322 }
323 }
324
313 /// Create a new [`Sender`] for the `Watch`. 325 /// Create a new [`Sender`] for the `Watch`.
314 pub fn sender(&self) -> Sender<'_, M, T, N> { 326 pub fn sender(&self) -> Sender<'_, M, T, N> {
315 Sender(Snd::new(self)) 327 Sender(Snd::new(self))