Help us shape the future of Go! Take the 2026 Go Developer Survey

lockfile

package module
v0.0.0-...-fccf54c Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2017 License: ISC Imports: 4 Imported by: 0

README

lockfile - package that manages filesystem locks.

The lockfile package uses the filesystem to serialize cooperative processes. Additionally it provides single process serialization.

Typical usage:

	// Create lock
	l, err := New(lockfile, 100*time.Millisecond)
	if err != nil {
		return err
	}

	...

	// Lock something
	err = l.Lock(5*time.Second)
	if err != nil {
		return err
	}

	...

	// And unlock it
	err = l.Unlock()
	if err != nil {
		return err
	}

Documentation

Overview

lockfile - package that manages filesystem locks.

This package enables the caller to use filesystem locks. It uses the operating system file creation system call with the exclusive flag.

This package relies on callers to always check errors. Failure to do so may result in corruption.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout = errors.New("timeout")
)

Functions

This section is empty.

Types

type LockFile

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

LockFile opaque type that contains the lockfile context.

func New

func New(dirname string, resolution time.Duration) (*LockFile, error)

New returns a LockFile context if the directory is writable.

func (*LockFile) Lock

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

Lock attempts to create a lock file within the given timeout. If the lock can not be obtained within the given timeout or due to a filesystem error it returns failure. The caller must check the error.

func (*LockFile) Resolution

func (l *LockFile) Resolution(resolution time.Duration)

Resolution sets the retry resolution. The default retry resolution is 100ms.

func (*LockFile) TryLock

func (l *LockFile) TryLock() bool

func (*LockFile) Unlock

func (l *LockFile) Unlock() error

Unlock attempts to unlock by removing the lock file. The caller must check the error.

Jump to

Keyboard shortcuts

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