Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
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.
The npm package level-mutex receives a total of 0 weekly downloads. As such, level-mutex popularity was classified as not popular.
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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.