Type Alias IDatabaseSemaphoreTransaction

IDatabaseSemaphoreTransaction: {
    findSemaphore(
        context: IReadableContext,
        key: string,
    ): Promise<null | ISemaphoreData>;
    findSlots(
        context: IReadableContext,
        key: string,
    ): Promise<ISemaphoreSlotData[]>;
    upsertSemaphore(
        context: IReadableContext,
        key: string,
        limit: number,
    ): Promise<void>;
    upsertSlot(
        context: IReadableContext,
        key: string,
        slotId: string,
        expiration: null | Date,
    ): Promise<void>;
}

Transaction context for atomic semaphore operations. Provides methods to read and modify semaphore state within a database transaction.

All transaction methods must be executed together atomically. The database guarantees isolation (race-condition free) for all operations.

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

Type declaration

  • findSemaphore:function
  • findSlots:function
  • upsertSemaphore:function
    • Creates new semaphore or updates existing semaphore limit. Idempotent: calling multiple times with same limit is safe.

      Parameters

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        The semaphore identifier

      • limit: number

        Maximum number of concurrent slots

      Returns Promise<void>

      Void (always succeeds)

  • upsertSlot:function
    • Creates new slot or updates existing slot expiration. Called when a request acquires a slot (with expiration time). Idempotent: updating same slot's expiration is safe.

      Parameters

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        The semaphore identifier

      • slotId: string

        Unique slot identifier (generated by consumer)

      • expiration: null | Date

        When slot expires and becomes available again, or null for no expiration

      Returns Promise<void>

      Void (always succeeds)