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

    Class MemoryLock

    In-process Lock backed by a Map, with TTL expiry evaluated via an injected Clock.

    Provides real mutual exclusion within a single process. An expired lock is treated as free on the next acquisition attempt. Not suitable for coordinating across processes or hosts.

    const lock = new MemoryLock()
    const token = await lock.acquire('room:1', 5000)
    if (token) {
    try {
    // ...critical section...
    } finally {
    await lock.release('room:1', token)
    }
    }

    Implements

    Index

    Constructors

    Methods

    Constructors

    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.