simplify lock/semaphore - #718
Closed
arnetheduck wants to merge 1 commit into
Closed
Conversation
`AsyncLock` is a special case of `AsyncSemaphore` (with size 1) - make sure that they both behave the same. In particular, simpify the `AsyncLock` implementation to use fewer poll rounds and futures during `acquire` while maintaining the same fairness guarantees as before. Also, add `tryAcquire` and `tryRelease` which are exception-free variants of the existing functions - in particular, `release` is annoying to use in `finally` with `raises: []` since it then requires an exception handler that never gets triggered. * release cancelled futures during `acquire` as well as `release`.
Member
Author
|
The alternative to adding |
etan-status
reviewed
Aug 28, 2026
|
|
||
| fut | ||
|
|
||
| proc tryRelease*(lock: AsyncLock): bool = |
Contributor
There was a problem hiding this comment.
Suggested change
| proc tryRelease*(lock: AsyncLock): bool = | |
| proc tryRelease*(lock: AsyncLock): bool {.discardable.} = |
Contributor
There was a problem hiding this comment.
But in a way, discarding it isn't safe either. If there are logic bugs in the code, it just hides them...
Member
Author
|
Going with #721 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AsyncLockis a special case ofAsyncSemaphore(with size 1) - make sure that they both behave the same.In particular, simpify the
AsyncLockimplementation to use fewer poll rounds and futures duringacquirewhile maintaining the same fairness guarantees as before.Also, add
tryAcquireandtryReleasewhich are exception-free variants of the existing functions - in particular,releaseis annoying to use infinallywithraises: []since it then requires an exception handler that never gets triggered.acquireas well asrelease.