Type Alias ILockBase

ILockBase: {
    acquire(): Promise<boolean>;
    acquireOrFail(): Promise<void>;
    forceRelease(): Promise<boolean>;
    refresh(ttl?: ITimeSpan): Promise<boolean>;
    refreshOrFail(ttl?: ITimeSpan): Promise<void>;
    release(): Promise<boolean>;
    releaseOrFail(): Promise<void>;
    runOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>): Promise<TValue>;
}

Base operations for managing lock acquisition, release, and refresh cycles. Provides both safe (boolean-returning) and strict (error-throwing) versions of lock operations.

IMPORT_PATH: "@daiso-tech/core/lock/contracts"

Type declaration

  • acquire:function
    • Attempts to acquire the lock if not already held by another owner.

      Returns Promise<boolean>

      true if lock was successfully acquired, false if already held by a different owner

  • acquireOrFail:function
    • Acquires the lock if not already held by another owner. Throws an error if the lock cannot be acquired.

      Returns Promise<void>

      If the lock is already held by a different owner

  • forceRelease:function
    • Forces lock release regardless of current owner. Use with caution as it can break lock guarantees.

      Returns Promise<boolean>

      true if the lock existed and was released, false if lock does not exist

  • refresh:function
    • Refreshes (extends) the lock's TTL if it is expirable and held by this owner. Updates the expiration time to prevent the lock from timing out.

      Parameters

      • Optionalttl: ITimeSpan

        New TTL duration. If not provided, uses the lock's original TTL

      Returns Promise<boolean>

      true if lock was successfully refreshed, false if not held by this owner or unexpirable

  • refreshOrFail:function
    • Refreshes (extends) the lock's TTL if it is expirable and held by this owner. Throws an error if the lock cannot be refreshed.

      Parameters

      • Optionalttl: ITimeSpan

        New TTL duration. If not provided, uses the lock's original TTL

      Returns Promise<void>

      If the lock is not held by this owner or is not expirable

  • release:function
    • Releases the lock if held by this owner.

      Returns Promise<boolean>

      true if lock was successfully released, false if not held by this owner

  • releaseOrFail:function
    • Releases the lock if held by this owner. Throws an error if the lock is not held by this owner.

      Returns Promise<void>

      If the lock is not held by this owner

  • runOrFail:function
    • Executes an async function while holding the lock. Automatically acquires the lock before execution and releases it after completion. Throws an error if the lock cannot be acquired.

      Type Parameters

      • TValue = void

        The return type of the async function

      Parameters

      Returns Promise<TValue>

      The return value of the function

      If the lock is already held by a different owner