-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync: add
watch::Receiver::mark_unseen
(#5962)
- Loading branch information
1 parent
1c428cc
commit 61042b4
Showing
2 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,7 +380,17 @@ mod state { | |
impl Version { | ||
/// Get the initial version when creating the channel. | ||
pub(super) fn initial() -> Self { | ||
Version(0) | ||
// The initial version is 1 so that `mark_unseen` can decrement by one. | ||
// (The value is 2 due to the closed bit.) | ||
Version(2) | ||
} | ||
|
||
/// Decrements the version. | ||
pub(super) fn decrement(&mut self) { | ||
// Decrement by two to avoid touching the CLOSED bit. | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if self.0 >= 2 { | ||
self.0 -= 2; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -400,7 +410,7 @@ mod state { | |
/// Create a new `AtomicState` that is not closed and which has the | ||
/// version set to `Version::initial()`. | ||
pub(super) fn new() -> Self { | ||
AtomicState(AtomicUsize::new(0)) | ||
AtomicState(AtomicUsize::new(2)) | ||
} | ||
|
||
/// Load the current value of the state. | ||
|
@@ -634,6 +644,11 @@ impl<T> Receiver<T> { | |
Ok(self.version != new_version) | ||
} | ||
|
||
/// Marks the state as unseen. | ||
pub fn mark_unseen(&mut self) { | ||
This comment has been minimized.
Sorry, something went wrong.
uklotzde
Contributor
|
||
self.version.decrement(); | ||
} | ||
|
||
/// Waits for a change notification, then marks the newest value as seen. | ||
/// | ||
/// If the newest value in the channel has not yet been marked seen when | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
decrement()
is not needed for anything else than marking the current version as unchanged/unseen.The special value
0
seems to be a better choice for this purpose, no conditional needed. This special value is already used implicitly when decrementing the initial version.