@matrixai/async-locks
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -15,3 +15,2 @@ import type { MutexInterface } from 'async-mutex'; | ||
protected _writerCount: number; | ||
protected activeLock: 'read' | 'write' | null; | ||
lock(type: 'read' | 'write', timeout?: number): ResourceAcquire<RWLockReader>; | ||
@@ -27,3 +26,3 @@ read(timeout?: number): ResourceAcquire<RWLockReader>; | ||
*/ | ||
isLocked(type?: 'read' | 'write'): boolean; | ||
isLocked(): boolean; | ||
waitForUnlock(timeout?: number): Promise<void>; | ||
@@ -30,0 +29,0 @@ withF<T>(...params: [ |
@@ -17,3 +17,2 @@ "use strict"; | ||
this._writerCount = 0; | ||
this.activeLock = null; | ||
} | ||
@@ -62,7 +61,5 @@ lock(type, timeout) { | ||
readersRelease(); | ||
this.activeLock = 'read'; | ||
} | ||
else { | ||
readersRelease(); | ||
this.activeLock = 'read'; | ||
// Yield for the first reader to finish locking | ||
@@ -80,3 +77,2 @@ await (0, utils_1.yieldMicro)(); | ||
readersRelease(); | ||
this.activeLock = null; | ||
// Allow semaphore to settle https://github.com/DirtyHairy/async-mutex/issues/54 | ||
@@ -104,3 +100,2 @@ await (0, utils_1.yieldMicro)(); | ||
} | ||
this.activeLock = 'write'; | ||
return [ | ||
@@ -110,3 +105,2 @@ async () => { | ||
--this._writerCount; | ||
this.activeLock = null; | ||
// Allow semaphore to settle https://github.com/DirtyHairy/async-mutex/issues/54 | ||
@@ -132,10 +126,4 @@ await (0, utils_1.yieldMicro)(); | ||
*/ | ||
isLocked(type) { | ||
if (type != null) { | ||
return (this.activeLock === type && | ||
(this.readersLock.isLocked() || this.writersLock.isLocked())); | ||
} | ||
else { | ||
return this.readersLock.isLocked() || this.writersLock.isLocked(); | ||
} | ||
isLocked() { | ||
return this.readersLock.isLocked() || this.writersLock.isLocked(); | ||
} | ||
@@ -142,0 +130,0 @@ async waitForUnlock(timeout) { |
@@ -15,3 +15,2 @@ import type { MutexInterface } from 'async-mutex'; | ||
protected _writerCount: number; | ||
protected activeLock: 'read' | 'write' | null; | ||
lock(type: 'read' | 'write', timeout?: number): ResourceAcquire<RWLockWriter>; | ||
@@ -18,0 +17,0 @@ read(timeout?: number): ResourceAcquire<RWLockWriter>; |
@@ -18,3 +18,2 @@ "use strict"; | ||
this._writerCount = 0; | ||
this.activeLock = null; | ||
} | ||
@@ -67,6 +66,4 @@ lock(type, timeout) { | ||
} | ||
this.activeLock = 'read'; | ||
} | ||
else { | ||
this.activeLock = 'read'; | ||
// Yield for the first reader to finish locking | ||
@@ -81,3 +78,2 @@ await (0, utils_1.yieldMicro)(); | ||
this.readersRelease(); | ||
this.activeLock = null; | ||
// Allow semaphore to settle https://github.com/DirtyHairy/async-mutex/issues/54 | ||
@@ -122,3 +118,2 @@ await (0, utils_1.yieldMicro)(); | ||
} | ||
this.activeLock = 'write'; | ||
return [ | ||
@@ -129,3 +124,2 @@ async () => { | ||
--this._writerCount; | ||
this.activeLock = null; | ||
// Allow semaphore to settle https://github.com/DirtyHairy/async-mutex/issues/54 | ||
@@ -152,6 +146,8 @@ await (0, utils_1.yieldMicro)(); | ||
isLocked(type) { | ||
if (type != null) { | ||
return (this.activeLock === type && | ||
(this.readersLock.isLocked() || this.writersLock.isLocked())); | ||
if (type === 'read') { | ||
return this.readersLock.isLocked(); | ||
} | ||
else if (type === 'write') { | ||
return this.writersLock.isLocked(); | ||
} | ||
else { | ||
@@ -158,0 +154,0 @@ return this.readersLock.isLocked() || this.writersLock.isLocked(); |
{ | ||
"name": "@matrixai/async-locks", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"author": "Roger Qiu", | ||
@@ -5,0 +5,0 @@ "description": "Asynchronous locking utilities", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
63286
839