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.
Summary
This is an alternative implementation of
withSemaphore
introduced by #331.It's different in a few notable ways:
withCapacity
(on the fence about this, but I think it's less jargon-y thanwithSemaphore
and that's probably a good thing)acquire
/release
and I'm leaning toward that being a good thing, though I want to be sure I'm not overlooking an important use case (maybe @hugo082 can clarify this). Side note: Perhaps, in the future, we should consider adding “lower level” (i.e. more error prone, yet more control) variants asclass
implementations, which might be where the acquire/release paradigm feels more appropriate.getRunning(): number
, there's ahasCapacity(weight?: number): boolean
method. I'm not sure what the use case is for getting the current number of locks, so I'm hoping @hugo082 can clarify.withMutex
This PR doesn't have a
withMutex
function, and I'm still on the fence about it being a good addition, since it's easy enough to usewithCapacity(1, …)
for the same behavior? More clarity on this would be great.Related issue, if any:
#331
For any code change,
Does this PR introduce a breaking change?
No