lock

package
v0.18.6 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package lock provides an advisory file lock around the critical section that mutates tasks.txt (SPEC §6.4). It locks a dedicated lock file — never tasks.txt itself — so the atomic rename that replaces tasks.txt can't swap the inode out from under a held lock.

The OS primitive differs per platform: flock(2) on Unix, LockFileEx on Windows (see lock_unix.go / lock_windows.go). Both are advisory and released automatically when the file handle closes or the process exits, so a crash can't strand the store. Both are local-filesystem only; on NFS/SMB the lock may silently no-op, so the store is documented as local-FS only for concurrent access.

Index

Constants

View Source
const DefaultTimeout = 2 * time.Second

DefaultTimeout bounds how long Acquire waits before reporting the store busy.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handle

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

Handle is a held lock. Release must be called (typically via defer).

func Acquire

func Acquire(path string, timeout time.Duration) (*Handle, error)

Acquire takes an exclusive advisory lock on path, waiting up to timeout. It returns a clear "store is busy" error rather than blocking forever or silently succeeding. The OS lock primitive is non-blocking (tryLockExclusive) and we poll, so the timeout is honored on every platform.

func (*Handle) Release

func (h *Handle) Release() error

Release unlocks and closes the lock file.

Jump to

Keyboard shortcuts

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