aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync
diff options
context:
space:
mode:
authorBronson <[email protected]>2024-11-10 12:50:11 +1030
committerBronson <[email protected]>2024-11-10 12:50:11 +1030
commitf9a1511de4d3972da0fd4f7367043a65c673c593 (patch)
tree8fe0040e3089ade3b2fcd54962ed705cca4c9873 /embassy-sync
parentdc9fc73704b5fc18e9f34a2fc94c06bbe691732a (diff)
add default data to watch new()
Diffstat (limited to 'embassy-sync')
-rw-r--r--embassy-sync/src/watch.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/embassy-sync/src/watch.rs b/embassy-sync/src/watch.rs
index 59798d04f..e0f5e14f9 100644
--- a/embassy-sync/src/watch.rs
+++ b/embassy-sync/src/watch.rs
@@ -31,7 +31,7 @@ use crate::waitqueue::MultiWakerRegistration;
31/// 31///
32/// let f = async { 32/// let f = async {
33/// 33///
34/// static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(); 34/// static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(None);
35/// 35///
36/// // Obtain receivers and sender 36/// // Obtain receivers and sender
37/// let mut rcv0 = WATCH.receiver().unwrap(); 37/// let mut rcv0 = WATCH.receiver().unwrap();
@@ -299,10 +299,10 @@ impl<M: RawMutex, T: Clone, const N: usize> WatchBehavior<T> for Watch<M, T, N>
299 299
300impl<M: RawMutex, T: Clone, const N: usize> Watch<M, T, N> { 300impl<M: RawMutex, T: Clone, const N: usize> Watch<M, T, N> {
301 /// Create a new `Watch` channel. 301 /// Create a new `Watch` channel.
302 pub const fn new() -> Self { 302 pub const fn new(data: Option<T>) -> Self {
303 Self { 303 Self {
304 mutex: Mutex::new(RefCell::new(WatchState { 304 mutex: Mutex::new(RefCell::new(WatchState {
305 data: None, 305 data,
306 current_id: 0, 306 current_id: 0,
307 wakers: MultiWakerRegistration::new(), 307 wakers: MultiWakerRegistration::new(),
308 receiver_count: 0, 308 receiver_count: 0,
@@ -775,7 +775,7 @@ mod tests {
775 #[test] 775 #[test]
776 fn multiple_sends() { 776 fn multiple_sends() {
777 let f = async { 777 let f = async {
778 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(); 778 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(None);
779 779
780 // Obtain receiver and sender 780 // Obtain receiver and sender
781 let mut rcv = WATCH.receiver().unwrap(); 781 let mut rcv = WATCH.receiver().unwrap();
@@ -801,7 +801,7 @@ mod tests {
801 #[test] 801 #[test]
802 fn all_try_get() { 802 fn all_try_get() {
803 let f = async { 803 let f = async {
804 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(); 804 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(None);
805 805
806 // Obtain receiver and sender 806 // Obtain receiver and sender
807 let mut rcv = WATCH.receiver().unwrap(); 807 let mut rcv = WATCH.receiver().unwrap();
@@ -835,7 +835,7 @@ mod tests {
835 static CONFIG0: u8 = 10; 835 static CONFIG0: u8 = 10;
836 static CONFIG1: u8 = 20; 836 static CONFIG1: u8 = 20;
837 837
838 static WATCH: Watch<CriticalSectionRawMutex, &'static u8, 1> = Watch::new(); 838 static WATCH: Watch<CriticalSectionRawMutex, &'static u8, 1> = Watch::new(None);
839 839
840 // Obtain receiver and sender 840 // Obtain receiver and sender
841 let mut rcv = WATCH.receiver().unwrap(); 841 let mut rcv = WATCH.receiver().unwrap();
@@ -867,7 +867,7 @@ mod tests {
867 #[test] 867 #[test]
868 fn sender_modify() { 868 fn sender_modify() {
869 let f = async { 869 let f = async {
870 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(); 870 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(None);
871 871
872 // Obtain receiver and sender 872 // Obtain receiver and sender
873 let mut rcv = WATCH.receiver().unwrap(); 873 let mut rcv = WATCH.receiver().unwrap();
@@ -894,7 +894,7 @@ mod tests {
894 #[test] 894 #[test]
895 fn predicate_fn() { 895 fn predicate_fn() {
896 let f = async { 896 let f = async {
897 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(); 897 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(None);
898 898
899 // Obtain receiver and sender 899 // Obtain receiver and sender
900 let mut rcv = WATCH.receiver().unwrap(); 900 let mut rcv = WATCH.receiver().unwrap();
@@ -923,7 +923,7 @@ mod tests {
923 #[test] 923 #[test]
924 fn receive_after_create() { 924 fn receive_after_create() {
925 let f = async { 925 let f = async {
926 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(); 926 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(None);
927 927
928 // Obtain sender and send value 928 // Obtain sender and send value
929 let snd = WATCH.sender(); 929 let snd = WATCH.sender();
@@ -939,7 +939,7 @@ mod tests {
939 #[test] 939 #[test]
940 fn max_receivers_drop() { 940 fn max_receivers_drop() {
941 let f = async { 941 let f = async {
942 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(); 942 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(None);
943 943
944 // Try to create 3 receivers (only 2 can exist at once) 944 // Try to create 3 receivers (only 2 can exist at once)
945 let rcv0 = WATCH.receiver(); 945 let rcv0 = WATCH.receiver();
@@ -964,7 +964,7 @@ mod tests {
964 #[test] 964 #[test]
965 fn multiple_receivers() { 965 fn multiple_receivers() {
966 let f = async { 966 let f = async {
967 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(); 967 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(None);
968 968
969 // Obtain receivers and sender 969 // Obtain receivers and sender
970 let mut rcv0 = WATCH.receiver().unwrap(); 970 let mut rcv0 = WATCH.receiver().unwrap();
@@ -989,7 +989,7 @@ mod tests {
989 fn clone_senders() { 989 fn clone_senders() {
990 let f = async { 990 let f = async {
991 // Obtain different ways to send 991 // Obtain different ways to send
992 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(); 992 static WATCH: Watch<CriticalSectionRawMutex, u8, 1> = Watch::new(None);
993 let snd0 = WATCH.sender(); 993 let snd0 = WATCH.sender();
994 let snd1 = snd0.clone(); 994 let snd1 = snd0.clone();
995 995
@@ -1010,7 +1010,7 @@ mod tests {
1010 #[test] 1010 #[test]
1011 fn use_dynamics() { 1011 fn use_dynamics() {
1012 let f = async { 1012 let f = async {
1013 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(); 1013 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(None);
1014 1014
1015 // Obtain receiver and sender 1015 // Obtain receiver and sender
1016 let mut anon_rcv = WATCH.dyn_anon_receiver(); 1016 let mut anon_rcv = WATCH.dyn_anon_receiver();
@@ -1031,7 +1031,7 @@ mod tests {
1031 #[test] 1031 #[test]
1032 fn convert_to_dyn() { 1032 fn convert_to_dyn() {
1033 let f = async { 1033 let f = async {
1034 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(); 1034 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(None);
1035 1035
1036 // Obtain receiver and sender 1036 // Obtain receiver and sender
1037 let anon_rcv = WATCH.anon_receiver(); 1037 let anon_rcv = WATCH.anon_receiver();
@@ -1057,7 +1057,7 @@ mod tests {
1057 #[test] 1057 #[test]
1058 fn dynamic_receiver_count() { 1058 fn dynamic_receiver_count() {
1059 let f = async { 1059 let f = async {
1060 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(); 1060 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(None);
1061 1061
1062 // Obtain receiver and sender 1062 // Obtain receiver and sender
1063 let rcv0 = WATCH.receiver(); 1063 let rcv0 = WATCH.receiver();
@@ -1087,7 +1087,7 @@ mod tests {
1087 #[test] 1087 #[test]
1088 fn contains_value() { 1088 fn contains_value() {
1089 let f = async { 1089 let f = async {
1090 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(); 1090 static WATCH: Watch<CriticalSectionRawMutex, u8, 2> = Watch::new(None);
1091 1091
1092 // Obtain receiver and sender 1092 // Obtain receiver and sender
1093 let rcv = WATCH.receiver().unwrap(); 1093 let rcv = WATCH.receiver().unwrap();