setlock

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2015 License: MIT Imports: 4 Imported by: 0

README

go-setlock

Build Status wercker status Go Documentation GitHub release

go-setlock is a go port of setlock (an utility of daemontools), and accompanying library.

Command Usage

setlock [ -nNxXvV ] file program [ arg ... ]

Command Features

Command Installation

  • Download built archive from GitHub Releases and extract it
  • Or install by go get command: go get github.com/moznion/go-setlock/cmd/setlock

Library Usage

go-setlock provides file based exclusive lock functions by setlock package.
Please refer to the godoc: Go Documentation

Author

moznion (moznion@gmail.com)

Contributor

lestrrat

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFailedToAcquireLock represents error which is caused by failed to obtain a lock.
	ErrFailedToAcquireLock = errors.New("unable to lock file: temporary failure")
	// ErrLockFileEmpty represents error which is caused by empty lock file name is given.
	ErrLockFileEmpty = errors.New("unable to open: filaname must not be empty")
)

Functions

This section is empty.

Types

type Locker

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

Locker represents information of file based exclusive locking. This type implements sync.Locker and setlock.Setlocker.

func NewLocker

func NewLocker(filename string, nonblock bool) *Locker

NewLocker creates a new Locker object.

filename: Filename to use as lock file nonblock: Lock with non-blocking mode or not

func (*Locker) Lock

func (l *Locker) Lock()

Lock locks a file as exclusively.

If you use with blocking mode, Lock waits until obtaining a lock. Else if you use with non-blocking mode, Lock doesn't wait to obtain a lock (means Lock makes failure immediately if cannot obtain a lock).

This function makes panic if something is wrong. Highly recommend you to consider to use LockWithErr() instead, that can handle errors.

And YOU SHOULD NOT use this with non-blocking mode. Non-blocking mode makes panic immediately if it cannot obtain a lock (means it doesn't wait). Please use LockWithErr().

func (*Locker) LockWithErr

func (l *Locker) LockWithErr() error

LockWithErr locks a file as exclusively with error handling.

If you use with blocking mode, Lock waits until obtaining a lock. Else if you use with non-blocking mode, Lock doesn't wait to obtain a lock (means Lock makes failure immediately if cannot obtain a lock).

func (*Locker) Unlock

func (l *Locker) Unlock()

Unlock file resource.

type Setlocker

type Setlocker interface {
	LockWithErr() error
}

A Setlocker represents an object that can be locked with error handling.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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