-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
sync: clarify the behavior of tokio::sync::watch::Receiver
#7584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync: clarify the behavior of tokio::sync::watch::Receiver
#7584
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me. I'll wait a few days before merging, in case others are concerned about the behavior change.
Honestly, I'm somewhat concerned about this. Yes, the watch channel is kind of broken, but it's also used widely and I think lots of people out there rely on all sorts quirks of its behavior. I'm wary of changing it. |
@Darksonn 's concern is valid. At least, we can just fix the incorrect document of |
Thanks for the feedback @Darksonn. I understand the concern about breaking changes if downstream users depend on quirks of the watch API. I'm on the fence if it's a change that is likely of breaking downstream users:
If we're still concerned about breaking the above use case, I'm happy to revise the PR and only keep the documentation fix and regression tests. |
This is precisely why I'm so cautious about adding new features to |
Given that behavioral changes in tokio is always sensitive, I recommend the following approach. I prioritize backward compatibility and documentation clarity, even if it deviates from ideal principles of interface design.
Here are my rationales
|
Hi @DSharifi , are you still working on this PR? |
Err(RecvError)
in watch::Receiver::has_changed
for unseen valueswatch
documentation has_changed
and changed
watch
documentation has_changed
and changed
has_changed
and changed
Add empty between section title and text Co-authored-by: Qi <[email protected]>
Co-authored-by: Qi <[email protected]>
…b.com:DSharifi/tokio into dsharifi/watch-dont-return-error-unseen-value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
has_changed
and changed
tokio::sync::watch::Recevier
tokio::sync::watch::Recevier
tokio::sync::watch::Receiver
Motivation
Closes #7281 and supersedes #7556.
changed
has a documentation bug: its docs claimed it would error if and only if the channel was closed, but the implementation only returns an error when the channel is closed AND there are no unseen values.Solution
changed
has been updated to reflect its implementation.has_changed
's documentation has been updated to better highlight its difference withchanged
, as these methods fail on different conditions.watch
module documentation has been updated to reflect the difference betweenchanged
andhas_changed
.changed
andhas_changed
for closed channels.