diff options
| author | Dion Dokter <[email protected]> | 2022-06-16 14:19:16 +0200 |
|---|---|---|
| committer | Dion Dokter <[email protected]> | 2022-06-16 14:19:16 +0200 |
| commit | f92f46f489827ad9518d42c6bfa6d55fc6145bcf (patch) | |
| tree | 69336f0d0b470d9d3ab6b3401a380cf5e8ec317e | |
| parent | 790426e2f67ac5e2197139c354c3c201d098a59c (diff) | |
Added convenience methods that ignore lag
| -rw-r--r-- | embassy/src/channel/pubsub.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/embassy/src/channel/pubsub.rs b/embassy/src/channel/pubsub.rs index 4c360fea9..021225809 100644 --- a/embassy/src/channel/pubsub.rs +++ b/embassy/src/channel/pubsub.rs | |||
| @@ -274,6 +274,16 @@ impl<'a, T: Clone> Subscriber<'a, T> { | |||
| 274 | SubscriberWaitFuture { subscriber: self } | 274 | SubscriberWaitFuture { subscriber: self } |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | /// Wait for a published message (ignoring lag results) | ||
| 278 | pub async fn next_message_pure(&mut self) -> T { | ||
| 279 | loop { | ||
| 280 | match self.next_message().await { | ||
| 281 | WaitResult::Lagged(_) => continue, | ||
| 282 | WaitResult::Message(message) => break message, | ||
| 283 | } | ||
| 284 | } | ||
| 285 | } | ||
| 286 | |||
| 277 | /// Try to see if there's a published message we haven't received yet. | 287 | /// Try to see if there's a published message we haven't received yet. |
| 278 | /// | 288 | /// |
| 279 | /// This function does not peek. The message is received if there is one. | 289 | /// This function does not peek. The message is received if there is one. |
| @@ -289,6 +299,19 @@ impl<'a, T: Clone> Subscriber<'a, T> { | |||
| 289 | } | 299 | } |
| 290 | } | 300 | } |
| 291 | } | 301 | } |
| 302 | |||
| 303 | /// Try to see if there's a published message we haven't received yet (ignoring lag results). | ||
| 304 | /// | ||
| 305 | /// This function does not peek. The message is received if there is one. | ||
| 306 | pub fn try_next_message_pure(&mut self) -> Option<T> { | ||
| 307 | loop { | ||
| 308 | match self.try_next_message() { | ||
| 309 | Some(WaitResult::Lagged(_)) => continue, | ||
| 310 | Some(WaitResult::Message(message)) => break Some(message), | ||
| 311 | None => break None, | ||
| 312 | } | ||
| 313 | } | ||
| 314 | } | ||
| 292 | } | 315 | } |
| 293 | 316 | ||
| 294 | impl<'a, T: Clone> Drop for Subscriber<'a, T> { | 317 | impl<'a, T: Clone> Drop for Subscriber<'a, T> { |
