RTCForge API Reference v1.1.1
    Preparing search index...

    Interface Lock

    Distributed mutual-exclusion lock with fencing tokens and TTL-based expiry.

    Locks are used to serialize work that must not run concurrently across nodes (for example, ensuring a single owner processes a room). Each successful acquisition returns a unique token that must be presented to release, preventing one holder from releasing another's lock. Locks auto-expire after their TTL so a crashed holder cannot block others forever. The default in-process implementation is MemoryLock; production deployments can supply a Redis-backed adapter. Use noopLock to disable locking.

    interface Lock {
        acquire(key: string, ttlMs: number): Promise<string | null>;
        release(key: string, token: string): Promise<void>;
    }

    Implemented by

    Index

    Methods

    • Attempts to acquire the lock named key.

      Parameters

      • key: string

        The lock name.

      • ttlMs: number

        Lifetime of the lock in milliseconds; after this it expires and may be acquired by others.

      Returns Promise<string | null>

      A unique fencing token to pass to release on success, or null if the lock is currently held.

    • Releases a lock previously acquired with acquire.

      Parameters

      • key: string

        The lock name.

      • token: string

        The token returned by the matching acquire call.

      Returns Promise<void>

      A no-op if the lock is not held or the token does not match the current holder.