aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync/src/pubsub
diff options
context:
space:
mode:
authorDion Dokter <[email protected]>2022-09-29 15:15:10 +0200
committerDion Dokter <[email protected]>2022-09-29 15:15:10 +0200
commit874384826d4a6f9c9a9c8d3abf41f99a662f58fb (patch)
treeb902c0d546808b3f29c6c457a7303e86dee32752 /embassy-sync/src/pubsub
parentf4ebc36b638a081b4a8b68ae72c4cca5199c4c4c (diff)
Went back to named futures but now with must_use
Diffstat (limited to 'embassy-sync/src/pubsub')
-rw-r--r--embassy-sync/src/pubsub/mod.rs2
-rw-r--r--embassy-sync/src/pubsub/publisher.rs6
-rw-r--r--embassy-sync/src/pubsub/subscriber.rs7
3 files changed, 8 insertions, 7 deletions
diff --git a/embassy-sync/src/pubsub/mod.rs b/embassy-sync/src/pubsub/mod.rs
index 335d7e33e..faaf99dc6 100644
--- a/embassy-sync/src/pubsub/mod.rs
+++ b/embassy-sync/src/pubsub/mod.rs
@@ -562,7 +562,7 @@ mod tests {
562 async fn correct_available() { 562 async fn correct_available() {
563 let channel = PubSubChannel::<NoopRawMutex, u32, 4, 4, 4>::new(); 563 let channel = PubSubChannel::<NoopRawMutex, u32, 4, 4, 4>::new();
564 564
565 let mut sub0 = channel.subscriber().unwrap(); 565 let sub0 = channel.subscriber().unwrap();
566 let mut sub1 = channel.subscriber().unwrap(); 566 let mut sub1 = channel.subscriber().unwrap();
567 let pub0 = channel.publisher().unwrap(); 567 let pub0 = channel.publisher().unwrap();
568 568
diff --git a/embassy-sync/src/pubsub/publisher.rs b/embassy-sync/src/pubsub/publisher.rs
index 484f1dbfd..faa67d947 100644
--- a/embassy-sync/src/pubsub/publisher.rs
+++ b/embassy-sync/src/pubsub/publisher.rs
@@ -31,12 +31,11 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Pub<'a, PSB, T> {
31 } 31 }
32 32
33 /// Publish a message. But if the message queue is full, wait for all subscribers to have read the last message 33 /// Publish a message. But if the message queue is full, wait for all subscribers to have read the last message
34 pub async fn publish<'s>(&'s self, message: T) { 34 pub fn publish<'s>(&'s self, message: T) -> PublisherWaitFuture<'s, 'a, PSB, T> {
35 PublisherWaitFuture { 35 PublisherWaitFuture {
36 message: Some(message), 36 message: Some(message),
37 publisher: self, 37 publisher: self,
38 } 38 }
39 .await
40 } 39 }
41 40
42 /// Publish a message if there is space in the message queue 41 /// Publish a message if there is space in the message queue
@@ -167,7 +166,8 @@ impl<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS:
167} 166}
168 167
169/// Future for the publisher wait action 168/// Future for the publisher wait action
170struct PublisherWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { 169#[must_use = "futures do nothing unless you `.await` or poll them"]
170pub struct PublisherWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
171 /// The message we need to publish 171 /// The message we need to publish
172 message: Option<T>, 172 message: Option<T>,
173 publisher: &'s Pub<'a, PSB, T>, 173 publisher: &'s Pub<'a, PSB, T>,
diff --git a/embassy-sync/src/pubsub/subscriber.rs b/embassy-sync/src/pubsub/subscriber.rs
index 8a8e9144b..f420a75f0 100644
--- a/embassy-sync/src/pubsub/subscriber.rs
+++ b/embassy-sync/src/pubsub/subscriber.rs
@@ -28,8 +28,8 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Sub<'a, PSB, T> {
28 } 28 }
29 29
30 /// Wait for a published message 30 /// Wait for a published message
31 pub async fn next_message(&mut self) -> WaitResult<T> { 31 pub fn next_message<'s>(&'s mut self) -> SubscriberWaitFuture<'s, 'a, PSB, T> {
32 SubscriberWaitFuture { subscriber: self }.await 32 SubscriberWaitFuture { subscriber: self }
33 } 33 }
34 34
35 /// Wait for a published message (ignoring lag results) 35 /// Wait for a published message (ignoring lag results)
@@ -140,7 +140,8 @@ impl<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS:
140} 140}
141 141
142/// Future for the subscriber wait action 142/// Future for the subscriber wait action
143struct SubscriberWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { 143#[must_use = "futures do nothing unless you `.await` or poll them"]
144pub struct SubscriberWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
144 subscriber: &'s mut Sub<'a, PSB, T>, 145 subscriber: &'s mut Sub<'a, PSB, T>,
145} 146}
146 147