Went back to named futures but now with must_use
This commit is contained in:
parent
f4ebc36b63
commit
874384826d
@ -562,7 +562,7 @@ mod tests {
|
|||||||
async fn correct_available() {
|
async fn correct_available() {
|
||||||
let channel = PubSubChannel::<NoopRawMutex, u32, 4, 4, 4>::new();
|
let channel = PubSubChannel::<NoopRawMutex, u32, 4, 4, 4>::new();
|
||||||
|
|
||||||
let mut sub0 = channel.subscriber().unwrap();
|
let sub0 = channel.subscriber().unwrap();
|
||||||
let mut sub1 = channel.subscriber().unwrap();
|
let mut sub1 = channel.subscriber().unwrap();
|
||||||
let pub0 = channel.publisher().unwrap();
|
let pub0 = channel.publisher().unwrap();
|
||||||
|
|
||||||
|
@ -31,12 +31,11 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Pub<'a, PSB, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Publish a message. But if the message queue is full, wait for all subscribers to have read the last message
|
/// Publish a message. But if the message queue is full, wait for all subscribers to have read the last message
|
||||||
pub async fn publish<'s>(&'s self, message: T) {
|
pub fn publish<'s>(&'s self, message: T) -> PublisherWaitFuture<'s, 'a, PSB, T> {
|
||||||
PublisherWaitFuture {
|
PublisherWaitFuture {
|
||||||
message: Some(message),
|
message: Some(message),
|
||||||
publisher: self,
|
publisher: self,
|
||||||
}
|
}
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Publish a message if there is space in the message queue
|
/// 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:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Future for the publisher wait action
|
/// Future for the publisher wait action
|
||||||
struct PublisherWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
|
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
||||||
|
pub struct PublisherWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
|
||||||
/// The message we need to publish
|
/// The message we need to publish
|
||||||
message: Option<T>,
|
message: Option<T>,
|
||||||
publisher: &'s Pub<'a, PSB, T>,
|
publisher: &'s Pub<'a, PSB, T>,
|
||||||
|
@ -28,8 +28,8 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Sub<'a, PSB, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for a published message
|
/// Wait for a published message
|
||||||
pub async fn next_message(&mut self) -> WaitResult<T> {
|
pub fn next_message<'s>(&'s mut self) -> SubscriberWaitFuture<'s, 'a, PSB, T> {
|
||||||
SubscriberWaitFuture { subscriber: self }.await
|
SubscriberWaitFuture { subscriber: self }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for a published message (ignoring lag results)
|
/// 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:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Future for the subscriber wait action
|
/// Future for the subscriber wait action
|
||||||
struct SubscriberWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
|
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
||||||
|
pub struct SubscriberWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
|
||||||
subscriber: &'s mut Sub<'a, PSB, T>,
|
subscriber: &'s mut Sub<'a, PSB, T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user