Interface DistributedLock

example

Safely using a mutex by always releasing

// Ensure you import LockPowers
import { LockPowers } from "@andi/powers";

const mutex = await LockPowers.createMutex("my-lock");
try {
    // critical code
} finally {
    await mutex.release();
}

Can optionally handle errors with a catch block, but be sure to always call .release()

Hierarchy

Index

Accessors

identifier

  • get identifier(): string
  • internal

    identifier helpful for debugging

    Returns string

isAcquired

  • get isAcquired(): boolean
  • Returns boolean

key

  • get key(): string
  • Returns string

Methods

acquire

  • acquire(): Promise<void>
  • Attempt to acquire lock. @throws LockAcquireTimeoutError if lock is not acquired within the configured lockTimeout

    Returns Promise<void>

release

  • release(): Promise<void>
  • Release lock.

    Returns Promise<void>

tryAcquire

  • tryAcquire(): Promise<boolean>
  • Method to acquire lock. Will not throw an error if acquireTimeout occurs.

    Returns Promise<boolean>

Generated using TypeDoc