async-lock
Advanced tools
+2
-0
@@ -20,1 +20,3 @@ # Authors ordered by first contribution. | ||
| Tim Schmidt (https://github.com/taschmidt) | ||
| Motty Milshtein (https://github.com/mottymilshtein) | ||
+4
-0
@@ -0,1 +1,5 @@ | ||
| 1.4.0 | ||
| ================== | ||
| * add execution timeout (thank you @mottymilshtein) | ||
| 1.3.2 | ||
@@ -2,0 +6,0 @@ ================== |
+17
-0
@@ -26,2 +26,3 @@ 'use strict'; | ||
| this.maxOccupationTime = opts.maxOccupationTime || AsyncLock.DEFAULT_MAX_OCCUPATION_TIME; | ||
| this.maxExecutionTime = opts.maxExecutionTime || AsyncLock.DEFAULT_MAX_EXECUTION_TIME; | ||
| if (opts.maxPending === Infinity || (Number.isInteger(opts.maxPending) && opts.maxPending >= 0)) { | ||
@@ -36,2 +37,3 @@ this.maxPending = opts.maxPending; | ||
| AsyncLock.DEFAULT_MAX_OCCUPATION_TIME = 0; //Never | ||
| AsyncLock.DEFAULT_MAX_EXECUTION_TIME = 0; //Never | ||
| AsyncLock.DEFAULT_MAX_PENDING = 1000; | ||
@@ -77,2 +79,3 @@ | ||
| var occupationTimer = null; | ||
| var executionTimer = null; | ||
| var self = this; | ||
@@ -87,2 +90,7 @@ | ||
| if (executionTimer) { | ||
| clearTimeout(executionTimer); | ||
| executionTimer = null; | ||
| } | ||
| if (locked) { | ||
@@ -137,2 +145,11 @@ if (!!self.queues[key] && self.queues[key].length === 0) { | ||
| var maxExecutionTime = opts.maxExecutionTime || self.maxExecutionTime; | ||
| if (maxExecutionTime) { | ||
| executionTimer = setTimeout(function () { | ||
| if (!!self.queues[key]) { | ||
| done(locked, new Error('Maximum execution time is exceeded ' + key)); | ||
| } | ||
| }, maxExecutionTime); | ||
| } | ||
| // Callback mode | ||
@@ -139,0 +156,0 @@ if (fn.length === 1) { |
+1
-1
| { | ||
| "name": "async-lock", | ||
| "description": "Lock on asynchronous code", | ||
| "version": "1.3.2", | ||
| "version": "1.4.0", | ||
| "author": { | ||
@@ -6,0 +6,0 @@ "name": "Rogier Schouten", |
+7
-0
@@ -11,2 +11,3 @@ # async-lock | ||
| * Occupation time limit supported | ||
| * Execution time limit supported | ||
| * Pending task limit supported | ||
@@ -142,2 +143,8 @@ * Domain reentrant supported | ||
| // Specify max execution time - max amount of time allowed between acquiring the lock and completing execution | ||
| var lock = new AsyncLock({maxExecutionTime: 3000}); | ||
| lock.acquire(key, fn, function(err, ret) { | ||
| // execution time exceeded error will be returned here if job not completed in given time | ||
| }); | ||
| // Set max pending tasks - max number of tasks allowed in the queue at a time | ||
@@ -144,0 +151,0 @@ var lock = new AsyncLock({maxPending: 1000}); |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
18200
5.84%276
5.75%178
4.09%1
Infinity%