async-lock
Advanced tools
Comparing version 1.2.8 to 1.3.0
@@ -0,1 +1,5 @@ | ||
1.3.0 | ||
================== | ||
* Add maxOccupationTime option (Thank you @abozaralizadeh) | ||
1.2.8 | ||
@@ -2,0 +6,0 @@ ================== |
@@ -25,2 +25,3 @@ 'use strict'; | ||
this.timeout = opts.timeout || AsyncLock.DEFAULT_TIMEOUT; | ||
this.maxOccupationTime = opts.maxOccupationTime || AsyncLock.DEFAULT_MAX_OCCUPATION_TIME; | ||
if (opts.maxPending === Infinity || (Number.isInteger(opts.maxPending) && opts.maxPending >= 0)) { | ||
@@ -34,2 +35,3 @@ this.maxPending = opts.maxPending; | ||
AsyncLock.DEFAULT_TIMEOUT = 0; //Never | ||
AsyncLock.DEFAULT_MAX_OCCUPATION_TIME = 0; //Never | ||
AsyncLock.DEFAULT_MAX_PENDING = 1000; | ||
@@ -74,7 +76,14 @@ | ||
var timer = null; | ||
var occupationTimer = null; | ||
var self = this; | ||
var done = function (locked, err, ret) { | ||
if (occupationTimer) { | ||
clearTimeout(occupationTimer); | ||
occupationTimer = null; | ||
} | ||
if (locked) { | ||
if (self.queues[key].length === 0) { | ||
if (!!self.queues[key] && self.queues[key].length === 0) { | ||
delete self.queues[key]; | ||
@@ -149,2 +158,3 @@ } | ||
}; | ||
if (self.domainReentrant && !!process.domain) { | ||
@@ -185,2 +195,11 @@ exec = process.domain.bind(exec); | ||
var maxOccupationTime = opts.maxOccupationTime || self.maxOccupationTime; | ||
if (maxOccupationTime) { | ||
occupationTimer = setTimeout(function () { | ||
if (!!self.queues[key]) { | ||
done(false, new Error('Maximum occupation time is exceeded')); | ||
} | ||
}, maxOccupationTime); | ||
} | ||
if (deferred) { | ||
@@ -187,0 +206,0 @@ return deferred; |
{ | ||
"name": "async-lock", | ||
"description": "Lock on asynchronous code", | ||
"version": "1.2.8", | ||
"version": "1.3.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Rogier Schouten", |
@@ -10,2 +10,3 @@ # async-lock | ||
* Timeout supported | ||
* Occupation time limit supported | ||
* Pending task limit supported | ||
@@ -135,2 +136,8 @@ * Domain reentrant supported | ||
// Specify max occupation time | ||
var lock = new AsyncLock({maxOccupationTime: 3000}); | ||
lock.acquire(key, fn, function(err, ret) { | ||
// occupation time exceeded error will be returned here if job not completed in given time | ||
}); | ||
// Set max pending tasks | ||
@@ -137,0 +144,0 @@ var lock = new AsyncLock({maxPending: 1000}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16257
254
171