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

Add Semaphore::add_permits() #44

Merged
merged 3 commits into from
May 27, 2023

Conversation

Jules-Bertholet
Copy link
Collaborator

@Jules-Bertholet Jules-Bertholet commented May 26, 2023

Allows increasing the permit count of the semaphore after creation.

Fixes #22

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Do you mind writing tests for this?

@Jules-Bertholet
Copy link
Collaborator Author

Test added

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but I'd prefer to test the edge case.

Could you add a test where you have an Acquire future that tries to acquire a permit on a zero-permit Semaphore? It should return Pending (use future::poll_once() to test this). Then, once the add_permits(1) function is called, it should resolve to Ready. It should also test using another Acquire that should not be woken up by this call.

@Jules-Bertholet
Copy link
Collaborator Author

Test added

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@notgull notgull merged commit 99a44a5 into smol-rs:master May 27, 2023
@Jules-Bertholet Jules-Bertholet deleted the semaphore-add-permits branch May 27, 2023 02:42
@notgull notgull mentioned this pull request Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: manually release semaphore permits
2 participants