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 ¶
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 ¶
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.
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.