Type Alias ISemaphoreAdapter

ISemaphoreAdapter: {
    acquire(settings: SemaphoreAcquireSettings): Promise<boolean>;
    forceReleaseAll(context: IReadableContext, key: string): Promise<boolean>;
    getState(
        context: IReadableContext,
        key: string,
    ): Promise<null | ISemaphoreAdapterState>;
    refresh(
        context: IReadableContext,
        key: string,
        slotId: string,
        ttl: TimeSpan,
    ): Promise<boolean>;
    release(
        context: IReadableContext,
        key: string,
        slotId: string,
    ): Promise<boolean>;
}

Technology-agnostic adapter contract for managing distributed semaphores. Implementations handle slot acquisition, release, refresh, and state tracking independent of the underlying storage. Note: This contract is low-level and typically not used directly - prefer ISemaphoreFactory for semaphore usage.

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

Type declaration

  • acquire:function
  • forceReleaseAll:function
    • Forcibly releases all slots for the specified semaphore regardless of ownership. Used for emergency cleanup or administrative operations. Bypasses ownership verification for situations where individual slot holders are unavailable.

      Parameters

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        Unique identifier for the semaphore

      Returns Promise<boolean>

      Promise resolving to true if the semaphore existed and slots were released, false if the semaphore doesn't exist or has no acquired slots

  • getState:function
  • refresh:function
    • Refreshes (extends) the time-to-live of an existing slot. Only succeeds if all conditions are met: the slot exists, hasn't expired, and is expirable.

      Parameters

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        Unique identifier for the semaphore

      • slotId: string

        Unique identifier of the slot to refresh

      • ttl: TimeSpan

        New time-to-live duration to set

      Returns Promise<boolean>

      Promise resolving to true if refresh succeeded, false if the slot is unexpirable, expired, or doesn't exist

  • release:function
    • Releases a specific slot if it is currently acquired. Only the holder of the slot (identified by slotId) can release it.

      Parameters

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        Unique identifier for the semaphore

      • slotId: string

        Unique identifier of the slot to release

      Returns Promise<boolean>

      Promise resolving to true if the slot was successfully released, false if the slot doesn't exist or is already released