Andi Skill Builder API Documentation

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()

Accessors

identifier

Get Signature

get identifier(): string;

Internal

identifier helpful for debugging

Returns

string


isAcquired

Get Signature

get isAcquired(): boolean;
Returns

boolean


key

Get Signature

get key(): string;
Returns

string

Methods

acquire()

acquire(): Promise<void>;

Attempt to acquire lock.

Returns

Promise<void>

Throws

LockAcquireTimeoutError if lock is not acquired within the configured lockTimeout


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>