filelock

package
v0.1.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package filelock is an exclusive inter-process lock on a private file: an SQLite write transaction, which the operating system releases however the holding process exits, so a lock is never stale.

The file is only ever opened through SQLite. On Unix, closing any other descriptor of a file drops every POSIX lock the process holds on it; SQLite keeps its own descriptors open while a lock is held, so probing a lock this process holds (Held) leaves it in place.

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = errors.New("locked")

ErrLocked reports a lock another holder has.

Functions

func Held

func Held(ctx context.Context, path string) (bool, error)

Held reports whether a holder (another process, or another Lock in this one) has the lock at path. A missing file is not held.

Types

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

Lock is a held lock.

func TryLock

func TryLock(ctx context.Context, path string) (*Lock, error)

TryLock takes the lock at path, creating the file with mode 0600, or returns ErrLocked at once.

func Wait

func Wait(ctx context.Context, path string, timeout time.Duration) (*Lock, error)

Wait retries TryLock until timeout.

func (*Lock) Release

func (l *Lock) Release() error

Release gives the lock up. It is safe on a nil or released lock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL