-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
7707 updated Tx struct and UnboundedSender to return message length #7092
7707 updated Tx struct and UnboundedSender to return message length #7092
Conversation
tokio/src/sync/mpsc/unbounded.rs
Outdated
@@ -675,6 +675,11 @@ impl<T> UnboundedSender<T> { | |||
pub fn weak_count(&self) -> usize { | |||
self.chan.weak_count() | |||
} | |||
|
|||
//Returns length of [`UnboundedSender`] semaphores /2, supposidly the number of messages. |
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.
Code docs start with ///
, and it probably shouldn't reveal the inner workings of the channel by refering to the semaphore, since its not really relevant to the end user.
Also "supposidly" should be "supposedly".
What @conradludgate said in their comment #7077 (comment), this probably implies that the len function itself should do the division itself. But I'd probably put this division in the chan.rs len
function
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.
updated comment and moved division into the chan.rs classes len function
tokio/src/sync/mpsc/chan.rs
Outdated
@@ -208,6 +208,10 @@ impl<T, S: Semaphore> Tx<T, S> { | |||
} | |||
notified.await; | |||
} | |||
|
|||
pub(crate) fn len(&self) -> usize { | |||
self.inner.tx_count.load(Ordering::SeqCst) |
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.
This tx_count
counts how many Sender
s are active, not how many messages are waiting
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.
wouldn't the number of senders imply the same number of semaphores -> 2x number of messages?
…d, updated comments to match coding standards
update recommended by #7077
simply they requested that we produce a len method that returns the length of messages in que for UnboundedSender struct
This should return the length of messages in que, though it will get it at an instance, thus as a threaded application may be inaccurate when the instance is updated simultaneously, though should be approximately correct for the time/instance of the method call.
no tests for this as there is not a test class for this file and associated structs (which needs to be rectified), same tests pass/ & fail as the regular master branch.
I've been looking for something to help contribute to this repo, though I'm new to rust, this repo, and my ide, so let me know what's wrong, what can be better, and what I'm missing.
hope this works for you and I hope to be a more useful contributor in the future.