Documentation
¶
Overview ¶
Package clonelock keeps one clone-changing job at a time on each clone: a worktree made or removed, a release, a hooks install, a checks run, a script, or a pull. A tool updating itself, or being installed, holds its folder the same way. A job that finds its clone busy learns what holds it, which the window shows: "A release is using acme-org/sdk right now."
A clone is keyed by paths.Resolved, so a path through a symbolic link shares the lock of the folder it names. The locks are in-process: they keep the app's own jobs apart, not another program's.
Index ¶
- Variables
- type BusyError
- type Holder
- type Kind
- type Set
- func (s *Set) Holder(path string) (Holder, bool)
- func (s *Set) Lock(ctx context.Context, path string, h Holder) (release func(), err error)
- func (s *Set) LockWaitingFor(ctx context.Context, path string, h Holder, waitFor func(held Holder) bool) (release func(), err error)
- func (s *Set) TryLock(path string, h Holder) (release func(), held Holder, ok bool)
Constants ¶
This section is empty.
Variables ¶
var ErrBusy = errors.New("the clone is busy")
ErrBusy is matched by every *BusyError.
Functions ¶
This section is empty.
Types ¶
type BusyError ¶
type BusyError struct {
Holder Holder
}
BusyError is returned for a clone another job holds, naming it. Its text is the holder's Sentence.
type Holder ¶
type Holder struct {
Kind Kind
// Repo is what the window calls the clone: its repository on GitHub, as in
// "acme-org/sdk", or else its folder. Empty, the sentence says "this clone".
Repo string
// Title is the run's title, and RunID the run, for the window to offer; a worktree
// change has neither.
Title string
RunID int64
}
Holder says what holds a clone, for the user.
type Kind ¶
type Kind string
Kind is the kind of job that holds a clone.
const ( KindRelease Kind = "release" KindHooks Kind = "hooks" KindChecks Kind = "checks" KindScript Kind = "script" KindWorktree Kind = "worktree" // KindPull is a clone's branch pulled from origin, fast-forward only. KindPull Kind = "gitPull" // KindUpdate is a tool updating itself, which holds the folder its copy is in, and // KindInstall the app installing a tool, which holds the folder it places it in. KindUpdate Kind = "update" KindInstall Kind = "install" // KindOrphan is a run from before the app restarted, still running, which the app // follows under a placeholder lock. KindOrphan Kind = "orphan" )
The kinds of job that hold a clone.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set holds a lock per clone. The zero Set is ready to use, and it is safe for concurrent use. One Set serves the whole app, so every job that changes a clone sees every other.
func (*Set) Holder ¶
Holder returns the job that holds path's clone, and true, or false when it is free.
func (*Set) Lock ¶
Lock takes path's clone for h, waiting while another job holds it, until ctx ends.
func (*Set) LockWaitingFor ¶
func (s *Set) LockWaitingFor(ctx context.Context, path string, h Holder, waitFor func(held Holder) bool, ) (release func(), err error)
LockWaitingFor takes path's clone for h. While a job that waitFor accepts holds it, it waits, until ctx ends; a job waitFor refuses fails it at once with a *BusyError naming that job. It fails at once, too, when ctx has already ended. A ctx that ends fails it with ctx.Err() itself, as a semaphore does, so callers word it as they word any other.