happy-rusty
    Preparing search index...

    Interface MutexGuard<T>

    A guard that provides access to the mutex-protected value.

    The guard must be released after use by calling unlock(). Failure to unlock will cause deadlock for subsequent lock attempts.

    interface MutexGuard<T> {
        "[toStringTag]": "MutexGuard";
        value: T;
        toString(): string;
        unlock(): void;
    }

    Type Parameters

    • T

      The type of the protected value.

    Index

    Properties

    "[toStringTag]": "MutexGuard"

    The well-known symbol Symbol.toStringTag used by Object.prototype.toString(). Returns 'MutexGuard' so that Object.prototype.toString.call(guard) produces '[object MutexGuard]'.

    value: T

    The protected value. Can be read or modified while the guard is held.

    const guard = await mutex.lock();
    console.log(guard.value); // Read value
    guard.value = newValue; // Modify value
    guard.unlock();

    Methods

    • Custom toString implementation.

      Returns string

      A string representation of the guard.

      const guard = await mutex.lock();
      console.log(guard.toString()); // 'MutexGuard(42)'
    • Releases the lock, allowing other waiters to acquire it.

      Must be called when done with the protected value. After calling unlock(), the guard should not be used.

      Returns void

      const guard = await mutex.lock();
      try {
      guard.value.push('item');
      } finally {
      guard.unlock();
      }