Skip to content

Commit

Permalink
doc: Express what the comment says.
Browse files Browse the repository at this point in the history
The comment says: “If multiple updates have happened without the
subscriber being polled, the next poll will skip all but the latest.”,
but the code shows a single `Observable::set` followed by two
`Subscriber::next`. I would personally expect the opposite.

This patch updates the example to get 2 `Observable::set` and 1
`Subscriber::next`. The rest of the example has been updated to increase
the illustration letter.
  • Loading branch information
Hywan committed Mar 22, 2024
1 parent 9559347 commit aac4e31
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions eyeball/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
//! // If multiple updates have happened without the subscriber being
//! // polled, the next poll will skip all but the latest.
//! Observable::set(&mut observable, "C".to_owned());
//! assert_eq!(subscriber1.next().await, Some("C".to_owned()));
//! assert_eq!(subscriber2.next().await, Some("C".to_owned()));
//! Observable::set(&mut observable, "D".to_owned());
//! assert_eq!(subscriber1.next().await, Some("D".to_owned()));
//! assert_eq!(subscriber2.next().await, Some("D".to_owned()));
//!
//! // You can even obtain the value without cloning the value, by
//! // using `.read()` (no waiting) or `.next_ref().await` (waits for
Expand All @@ -48,17 +49,17 @@
//! // However, note that while a read guard returned by `.read()` or
//! // `.next_ref().await` is alive, updating the observable is
//! // blocked.
//! Observable::set(&mut observable, "D".to_owned());
//! Observable::set(&mut observable, "E".to_owned());
//! {
//! let guard = subscriber1.next_ref().await.unwrap();
//! assert_eq!(*guard, "D");
//! assert_eq!(*guard, "E");
//! }
//!
//! // The latest value is kept alive by subscribers when the
//! // `Observable` is dropped.
//! drop(observable);
//! assert_eq!(subscriber1.get(), "D");
//! assert_eq!(*subscriber2.read(), "D");
//! assert_eq!(subscriber1.get(), "E");
//! assert_eq!(*subscriber2.read(), "E");
//! # }
//! ```
//!
Expand Down

0 comments on commit aac4e31

Please sign in to comment.