happy-rusty
    Preparing search index...

    Interface RwLockWriteGuard<T>

    A guard that provides exclusive write access to the RwLock-protected value.

    Only one write guard can exist at a time, and no read guards can be acquired while a write guard is held.

    1.8.0

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

    Type Parameters

    • T

      The type of the protected value.

    Index

    Properties

    "[toStringTag]": "RwLockWriteGuard"

    The well-known symbol Symbol.toStringTag used by Object.prototype.toString().

    value: T

    The protected value (read-write access).

    const guard = await rwlock.write();
    console.log(guard.value); // Read the value
    guard.value = newValue; // Modify the value
    guard.unlock();

    Methods

    • Downgrades this write guard to a read guard atomically.

      The write lock is converted to a read lock without releasing it, allowing other waiting readers to proceed concurrently. Pending writers continue to wait until all readers (including this one) release their locks.

      After calling downgrade(), this guard is invalidated and must not be used — accessing value or calling unlock() will throw.

      Equivalent to Rust's RwLockWriteGuard::downgrade (stabilized in Rust 1.92.0).

      Returns RwLockReadGuard<T>

      A new RwLockReadGuard<T> providing shared read access.

      1.10.0

      const guard = await rwlock.write();
      guard.value = newValue;
      // Downgrade to a read lock, releasing waiting readers
      const readGuard = guard.downgrade();
      try {
      console.log(readGuard.value); // other readers can proceed concurrently
      } finally {
      readGuard.unlock();
      }
    • Custom toString implementation.

      Returns string

      A string representation of the guard.

      const guard = await rwlock.write();
      console.log(guard.toString()); // 'RwLockWriteGuard(42)'
    • Releases the write lock.

      After calling unlock(), the guard should not be used.

      Returns void

      const guard = await rwlock.write();
      try {
      guard.value = newValue;
      } finally {
      guard.unlock();
      }