filelock

package
v0.0.0-...-5c9bec8 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTimeout indicates that the lock attempt timed out.
	ErrTimeout = errors.New("lock timeout exceeded")

	// ErrLocked indicates TryLock failed because the lock was already locked.
	ErrLocked = errors.New("file is already locked")
)

Functions

This section is empty.

Types

type Lock

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

Lock implements cross-process locks using syscalls. This implementation is based on flock syscall.

func New

func New(filename string) (*Lock, error)

New returns a new lock around the given file.

func (*Lock) Lock

func (l *Lock) Lock() error

Lock locks the lock. This call will block until the lock is available.

func (*Lock) LockWithTimeout

func (l *Lock) LockWithTimeout(timeout time.Duration) error

LockWithTimeout tries to lock the lock until the timeout expires. If the timeout expires, this method will return ErrTimeout.

func (*Lock) TryLock

func (l *Lock) TryLock() error

TryLock attempts to lock the lock. This method will return ErrLocked immediately if the lock cannot be acquired.

func (*Lock) Unlock

func (l *Lock) Unlock() error

Unlock unlocks the lock.

Jump to

Keyboard shortcuts

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