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

feat: add withSemaphore & withMutex function #331

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

hugo082
Copy link

@hugo082 hugo082 commented Dec 26, 2024

Summary

Implements the withSemaphore function which creates a semaphore

Related issue, if any:

Related discussion

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed
  • Release notes in next-minor.md or next-major.md have been added, if needed

Does this PR introduce a breaking change?

No

In addition

I struggled to initialize the function via the radashi cli because of No radashi dependency found in package.json error.

https://app.warp.dev/block/FMHVZF6RUhM2jAIiADsEUR

Bundle impact

Status File Size 1
A src/async/withMutex.ts 1422
A src/async/withSemaphore.ts 1250

Footnotes

  1. Function size includes the import dependencies of the function.

@hugo082 hugo082 requested a review from aleclarson as a code owner December 26, 2024 12:33
@hugo082 hugo082 changed the title feat: add withSemaphore function feat: add withSemaphore & withMutex function Dec 26, 2024
@MarlonPassos-git MarlonPassos-git added the new feature This PR adds a new function or extends an existing one label Dec 27, 2024
Comment on lines +30 to +32
* const limitedFn = withMutex(() => ...)
* limitedFn()
* limitedFn(() => ...)
Copy link
Member

Choose a reason for hiding this comment

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

This usage is not supported by the current type definitions. I assume we'll want to update this example, rather than allow overriding the base function?

Comment on lines +69 to +71
* const limitedFn = withSemaphore({ capacity: 2 }, () => ...)
* limitedFn()
* limitedFn(() => ...)
Copy link
Member

Choose a reason for hiding this comment

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

Same issue here

@aleclarson aleclarson mentioned this pull request Jan 5, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This PR adds a new function or extends an existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants