-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
sync: clarify the behavior of mpsc::Receiver::recv_many()
#7541
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 mpsc::Receiver::recv_many()
#7541
Conversation
|
I'm not sure this table is the right way to explain this. Here's the way I think of the method:
Perhaps we could say that async fn recv_many(&mut self, buffer: &mut Vec<T>, limit: usize) -> usize {
if limit == 0 {
return 0;
}
// Wait for at least one message (or channel close).
let Some(first_message) = self.recv().await else {
return 0;
};
buffer.push(first_message);
let mut num_pushed = 1;
// Try to get more messages, but don't sleep.
while num_pushed < limit {
if let Some(msg) = self.try_recv() {
buffer.push(msg);
num_pushed += 1;
} else {
break;
}
}
num_pushed
} |
@Darksonn I believe this is a better way, let me try to shorten this code snippet, and then update the PR. |
Co-authored-by: Alice Ryhl <[email protected]> Signed-off-by: ADD-SP <[email protected]>
071e084 to
b30f2a6
Compare
I think this is already the shortest version, so I just simple copy the above code. |
|
I think we should still have some text saying that receives "at least one message". |
Signed-off-by: ADD-SP <[email protected]>
Signed-off-by: ADD-SP <[email protected]>
Signed-off-by: ADD-SP <[email protected]>
|
This PR duplicates #7201, I've asked the author to see if they are still going to work on it. |
|
Closed this PR, see #7201 (comment). |
Closes #7540