Skip to main content
zerotal

Documentation


Documentation / @zerotal/core / lock / LockDriver

Interface: LockDriver

Defined in: lock/drivers/LockDriver.ts:10

Contract for lock storage backends.

Every method must be atomic at the driver level. The owner parameter prevents a process from releasing a lock it no longer holds (e.g. if the TTL expired and another process re-acquired).

Methods

acquire()

acquire(key, owner, ttlSeconds): Promise<boolean>

Defined in: lock/drivers/LockDriver.ts:15

Try to acquire the lock. Returns true when acquired, false if already held by another owner and not yet expired.

Parameters

key

string

owner

string

ttlSeconds

number

Returns

Promise<boolean>


release()

release(key, owner): Promise<boolean>

Defined in: lock/drivers/LockDriver.ts:22

Release the lock only if the caller is still the owner. Returns true when released, false if the lock was held by someone else (e.g. TTL expired and another process re-acquired).

Parameters

key

string

owner

string

Returns

Promise<boolean>


forceRelease()

forceRelease(key): Promise<void>

Defined in: lock/drivers/LockDriver.ts:25

Unconditionally delete the lock regardless of owner.

Parameters

key

string

Returns

Promise<void>


exists()

exists(key): Promise<boolean>

Defined in: lock/drivers/LockDriver.ts:28

Returns true if the lock is currently held (not expired).

Parameters

key

string

Returns

Promise<boolean>


dispose()?

optional dispose(): void

Defined in: lock/drivers/LockDriver.ts:31

Release background resources (timers, DB connections).

Returns

void