Skip to content
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: add len and is_empty methods to mpsc senders #7103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tqwewe
Copy link

@tqwewe tqwewe commented Jan 15, 2025

Motivation

Closes #7077

Tldr; adds len and is_empty methods to both bounded and unbounded Senders.

Solution

@conradludgate mentioned in the issue in a comment that the unbounded len can be derived from the seamphore's available permits / 2. However it seems like I didn't need to divide the semaphore available permits based on tests.

The implementation of len for bounded Sender did not use the semaphore's available permits directly, and instead used the semaphore's bound - available_permits.

I've added tests for these new methods which are passing.


Related PR #7092

@github-actions github-actions bot added the R-loom-sync Run loom sync tests on this PR label Jan 15, 2025
@maminrayej maminrayej added A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync R-loom-sync Run loom sync tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add .len() method to UnboundedSender
3 participants