await-lock | Mutex locks for async functions | Reactive Programming library
kandi X-RAY | await-lock Summary
kandi X-RAY | await-lock Summary
Mutex locks for async functions
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of await-lock
await-lock Key Features
await-lock Examples and Code Snippets
Community Discussions
Trending Discussions on await-lock
QUESTION
I'm somewhat new to the JavaScript/Typescript/Node/Express world, but from my research so far, there doesn't seem to be an 'accepted' way to lock critical sections of code in a Node/Express app. I've come across a couple of NPM packages (async-lock
, await-lock
, rwlock
), but they all have a surprisingly low download/week count and seem like they are not particularly well maintained (in that their last publishes are old, or the official maintainer explicitly says that he's not actively maintaining it). None seem to have TypeScript definitions (at least as far as I can tell). And, most problematically, none seem to have much in terms of documentation (beyond a couple examples to show the common-case usage). I've seen a few questions here where people have written their own (often active polling) locks (which seems sub-optimal), or suggest using a DB for locking (which seems like a heavyweight solution to a lightweight problem). async-lock
seems like the most popular of them (download-count-wise), but I'm a little wary of depending on something that the owner disclaims much responsibility for (and the Docs are quite thin).
My use-case seems pretty straight forward. I'm building a REST server, and the objects have some interdependencies. So, for instance, if someone is updating a FOO, and FOOs have references to BARs, then I'd want to lock my critical section on 'FOO' and 'BAR', then get the old FOO, any related BARs, validate the update, and write the new FOO back to the DB - after which I'd release the 'FOO' and 'BAR' locks.
So my question is this - for simple critical section locking in TypeScript (supporting multiple simultaneous locks/keys), what is the standard practice/API/package?
This is a single-server/single-DB application, so there's no need for distributed locks - just trying to deal with the fact that multiple requests are being handled simultaneously due to 'thread-switching' on asynchronous IO.
...ANSWER
Answered 2018-May-15 at 11:57There's no such built-in functionality in Node.js. A user can use third-party libraries or develop own solution.
async-lock
, the very first package you've listed, has considerable download stats, TypeScript definitions and is maintained.
Although a lot of small utility NPM packages may not be updated for years because they don't ever need that - and if they even do, they are simple enough to be forked, modified and optionally PRed.
This is a single-server/single-DB application, so there's no need for distributed locks - just trying to deal with the fact that multiple requests are being handled simultaneously due to 'thread-switching' on asynchronous IO.
Then it's likely a good use case for Node.js in-memory locks that don't need to be stored in database or filesystem.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install await-lock
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page