Skip to content

Commit

Permalink
fix: return Promise<Lock> on utility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AVVS committed Apr 20, 2021
1 parent c288bc5 commit b0aeb52
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class Lock {
*
* @param key The redis key to use for the lock
*/
async acquire(key: string): Promise<void> {
async acquire(key: string): Promise<Lock> {
if (this._locked) {
throw new LockAcquisitionError('Lock already held')
}
Expand All @@ -88,13 +88,15 @@ export class Lock {

throw err
}

return this
}

/**
* Attempts to extend the lock
* @param expire in `timeout` seconds
*/
async extend(time: number = this.config.timeout): Promise<void> {
async extend(time: number = this.config.timeout): Promise<Lock> {
const key = this._key
const client = this._client

Expand All @@ -105,7 +107,7 @@ export class Lock {
try {
const res = await client.pexpireifequal(key, this._id, time)
if (res) {
return
return this
}

this._locked = false
Expand All @@ -127,7 +129,7 @@ export class Lock {
* if no callback is supplied. If invoked in the context of a promise, it may
* throw a LockReleaseError.
*/
async release(): Promise<void> {
async release(): Promise<Lock> {
const key = this._key
const client = this._client

Expand All @@ -153,6 +155,8 @@ export class Lock {

throw err
}

return this
}

/**
Expand Down

0 comments on commit b0aeb52

Please sign in to comment.