Add pooling, semaphores, latches, and mutexes #222
Replies: 3 comments 12 replies
-
When creating this post, I had the wrong idea of what a semaphore is (I was really thinking of a latch, apparently). I believe #145 covers the use cases of a semaphore, though I could be wrong. If anyone has more familiarity, feel free to confirm or deny. I suppose a semaphore API could look more like a class, rather than the currying style of |
Beta Was this translation helpful? Give feedback.
-
Re: latch -- What kind of functionality are you thinking about beyond what |
Beta Was this translation helpful? Give feedback.
-
Here is some related functions proposal. I would love to get your feedbacks in order to send PRs. Proposal inspired from @shopify/semaphore, async-mutex & rust async_weighted_semaphore. Let me know that are the next steps.
|
Beta Was this translation helpful? Give feedback.
-
Pooling: Manages reusable objects to reduce creation/destruction overhead. Useful for expensive resources like database connections or complex data structures.
Semaphores: Limit concurrent asynchronous operations. Control simultaneous API calls or database queries to prevent resource exhaustion or rate limit breaches.
Latch: Coordinates multiple asynchronous operations, allowing you to wait until all are complete. Initializes with a count, decrements as operations finish, and resolves a promise when the count reaches zero.
Mutex: Ensures non-overlapping access to shared resources in asynchronous code. Implements critical sections for async operations, preventing interference when multiple async functions run concurrently.
These tools optimize resource management and control flow in JavaScript's asynchronous, event-driven environment.
We are currently taking suggestions on which popular NPM libraries to model our simple reimplementation on. Our goal is to mimic the API of a popular NPM library for each of these, so you can always upgrade to their more feature-rich implementations when/if you need it.
Beta Was this translation helpful? Give feedback.
All reactions