Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mutexify

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mutexify - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

16

index.js
var mutexify = function() {
var queue = []
var used = false
var used = null
var acquire = function(fn) {
var call = function () {
used(release)
}
var acquire = function (fn) {
if (used) return queue.push(fn)
used = true
fn(release)
used = fn
process.nextTick(call)
return 0
}
var release = function(fn, err, value) {
used = false
var release = function (fn, err, value) {
used = null
if (queue.length) acquire(queue.shift())

@@ -15,0 +19,0 @@ if (fn) fn(err, value)

{
"name": "mutexify",
"version": "1.0.1",
"version": "1.1.0",
"description": "mutex lock for javascript",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -34,2 +34,25 @@ var tape = require('tape')

})
})
})
tape('calls the locking callbacks in a different stack', function(t) {
t.plan(2)
var lock = mutexify()
var topScopeFinished = false
var secondScopeFinished = false
lock(function(release) {
t.ok(topScopeFinished, 'the test function has already finished running')
release()
secondScopeFinished = true
})
lock(function(release) {
t.ok(secondScopeFinished, 'the last lock\'s call stack is done')
release()
t.end()
})
topScopeFinished = true
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc