To utilize the MongodbSemaphoreAdapter, you must install the "mongodb" package.

Note in order to use MongodbSemaphoreAdapter correctly, ensure you use a single, consistent database across all server instances.

IMPORT_PATH: "@daiso-tech/core/semaphore/mongodb-semaphore-adapter"

Implements

Constructors

Methods

  • 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

    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

  • 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
    • 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

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

    Parameters

    • _context: IReadableContext
    • 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