Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
level-mutex
Advanced tools
npm install level-mutex
level-mutex
is an abstract "lock" around a levelup
store. What it does is cycle between reads and writes, allowing all writes to return in order while queuing all reads, the running all reads and returning in order, then writing all the pending reads again. level-mutex
uses node.js' single threaded nature to your advantage so that you can maintain a higher order locking structure to insure various types of read-on-write consistency semantics.
This is currently used in couchup to ensure users cannot update a document without providing the latest revision.
While you do scope level-mutex
to a single levelup store there is nothing stopping you from having many mutexes around the same store provided you're using each to manage a separate higher order consistency guarantee. For instance, couchup
uses a mutex per database and an indefinite number of databases might exist in a single levelup store.
var levelup = require('levelup')
, mutex = require('level-mutex')
;
var store = levelup('./testdb')
, mymutex = mutex(store)
, pending = []
;
function write (key, revision, value, cb) {
mymutex.get('key', function (e, val) {
// verify that the revision being written is the current one in the database
if (e || value.revision !=== revision) return cb(new Error('rev is out of date'))
// if this key is being written then nobody has read it yet which means
// someone writing it can't be writing to the new revision
if (pending.indexOf(key) !== -1) return cb(new Error('rev is out of date'))
pending.push(key)
// bump the rev
value.revision = value.revision + 1
mymutex.put(key, value, function (e) {
if (e) return cb(e)
cb(null, {rev:value.revision})
})
})
}
// flush all pending keys when writes have been flushed.
mymutex.on('flushed', function () {
pending = []
})
FAQs
Mutex read/write lock for levelup.
We found that level-mutex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.