filelock

package
v0.1.1230 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package filelock keeps a change to a file one at a time across the magpies on a computer: the gateway that runs all day, and each magpie run from a terminal or a script meanwhile.

Index

Constants

View Source
const Wait = 10 * time.Second

Wait is how long Mutex waits for another magpie to let go, before it goes on without the lock, as it did before there was one: a magpie stuck holding it (or two magpies each waiting on a lock the other holds) never hangs every other.

Variables

This section is empty.

Functions

func Lock

func Lock(path string, wait time.Duration) (unlock func(), held bool)

Lock takes the lock on the file at path, made if it isn't there, waiting up to wait for another process to let it go. The system holds it on the file and lets it go when the process holding it ends, however it ends, so none is ever left behind; the file stays, since taken away one process could hold the lock on it while another took one on a new file. held is false when it went on without the lock: on a file system without locks, or after wait.

func TryLock

func TryLock(f *os.File) (bool, error)

TryLock takes f's lock when no other process (or other descriptor of the file) holds it.

func Unlock

func Unlock(f *os.File)

Unlock lets f's lock go.

Types

type Mutex

type Mutex struct {

	// Path is the lock file: the file guarded, with ".lock".
	Path func() string
	// Locked, when set, is called once both locks are held: to have the
	// file guarded read afresh, not from what was parsed of it before
	// another magpie wrote it.
	Locked func()
	// contains filtered or unexported fields
}

Mutex is a sync.Mutex that also holds the lock on the file Path names while it is held, so a read, change and write of a file under it is one at a time across magpies too, not only within this one. Every read of the file a change is made from is to be made after Lock.

func (*Mutex) Lock

func (m *Mutex) Lock()

func (*Mutex) Unlock

func (m *Mutex) Unlock()

Jump to

Keyboard shortcuts

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