lock

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

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

Lock prevents code to run at the same time by using a lockfile

func NewLock

func NewLock(filename string) *Lock

NewLock creates a new lock

func (*Lock) ForceAcquire added in v0.9.2

func (l *Lock) ForceAcquire() bool

ForceAcquire returns true if the lock was successfully set.

If a lock file already exists, it reads the PID of the supposedly running process and check if it's still running. If there no more process with this PID, it will try to delete the lock, then recreate a new lock.

func (*Lock) HasLocked added in v0.9.2

func (l *Lock) HasLocked() bool

HasLocked check this instance (and only this one) has locked the file

func (*Lock) LastPID added in v0.9.2

func (l *Lock) LastPID() (int32, error)

LastPID returns the last PID written into the lock file.

func (*Lock) Release

func (l *Lock) Release()

Release the lockfile

func (*Lock) SetPID added in v0.9.2

func (l *Lock) SetPID(pid int)

SetPID writes down the PID in the lock file. You can run the method as many times as you want when the PID changes

func (*Lock) TryAcquire

func (l *Lock) TryAcquire() bool

TryAcquire returns true if the lock was successfully set. It returns false if a lock already exists

func (*Lock) Who

func (l *Lock) Who() (string, error)

Who owns the lock?

type SetPID added in v0.9.2

type SetPID func(pid int)

SetPID is a callback that writes the PID in the lockfile

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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