Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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).