Skip to content
FutureBlitz

    Install

    Import std.io.lock

    FileLock

    std.io.lock

    class

    Public Class FileLock

    A lock on a file, held for this FileLock alone, or shared with other shared ones, until Close, or until its last reference goes. The file is made, empty, when it isn't there, and stays when the lock goes. A FileLock waiting for one that this program holds waits forever.

    Examples

    Local folder = Try TempDir()
    Local path = folder.Path / "app.lock"
    Try File.WriteText(path, "")
    Local lock = Try FileLock.Acquire(path)
    Expect(lock.IsHeld())
    Expect((Try FileLock.TryAcquire(path)) == Null)
    lock.Close()
    Local again = Try FileLock.TryAcquire(path)
    Expect(again != Null)
    again?.Close()
    Try folder.Close()

    std/io/lock.fb, line 40

    • Public ReadOnly Field Path: Path field #

      The file it locks.

    • Public ReadOnly Field IsShared: Bool field #

      Whether it's a shared lock, which other shared ones can hold too, or an exclusive one.

    • Public Static Method Acquire(path: Path): FileLock Throws IOError static method #

      A lock on the file for this one alone, once no other holds one.

    • Public Static Async Method AcquireAsync(path: Path): FileLock Throws IOError static method #

      What Acquire does, without blocking its thread: a call gives its Task.

    • Public Static Method AcquireShared(path: Path): FileLock Throws IOError static method #

      A lock on the file that other shared ones can hold too, once no lock for one alone holds it.

    • Public Static Async Method AcquireSharedAsync(path: Path): FileLock Throws IOError static method #

      What AcquireShared does, without blocking its thread: a call gives its Task.

    • Public Static Method TryAcquire(path: Path): FileLock? Throws IOError static method #

      A lock for this one alone, or Null when another holds one now.

    • Public Static Method TryAcquireShared(path: Path): FileLock? Throws IOError static method #

      A shared lock, or Null when a lock for one alone holds the file now.

    • Public Method IsHeld(): Bool method #

      Whether it still holds its lock.

    • Public Method Close() method #

      Lets go of the lock, which a second Close leaves alone.

    Report an issue with this page or with FutureBlitz on GitHub.