aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/juju/fslock/README.md
blob: 4361b9dd0d819196f63b8b731116f29d20f7e57e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

# fslock [![GoDoc](https://godoc.org/github.com/juju/fslock?status.svg)](https://godoc.org/github.com/juju/fslock)
fslock provides a cross-process mutex based on file locks that works on windows and *nix platforms.


![fslock](https://cloud.githubusercontent.com/assets/3185864/15507515/f3351498-2199-11e6-9f37-bc59657a9e8c.jpg)

<sup><sub>image: [public domain](https://pixabay.com/en/encrypted-privacy-policy-445155/)
(don't ask)
</sub></sup>

fslock relies on LockFileEx on Windows and flock on \*nix systems.  The timeout 
feature uses overlapped IO on Windows, but on \*nix platforms, timing out
requires the use of a goroutine that will run until the lock is acquired,
regardless of timeout.  If you need to avoid this use of goroutines, poll
TryLock in a loop. 



## Variables
``` go
var ErrLocked error = trylockError("fslock is already locked")
```
ErrLocked indicates TryLock failed because the lock was already locked.

``` go
var ErrTimeout error = timeoutError("lock timeout exceeded")
```
ErrTimeout indicates that the lock attempt timed out.


## type Lock
``` go
type Lock struct {
    // contains filtered or unexported fields
}
```
Lock implements cross-process locks using syscalls.


### func New
``` go
func New(filename string) *Lock
```
New returns a new lock around the given file.


### func (\*Lock) Lock
``` go
func (l *Lock) Lock() error
```
Lock locks the lock.  This call will block until the lock is available.

### func (\*Lock) LockWithTimeout
``` go
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
``` go
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
``` go
func (l *Lock) Unlock() error
```
Unlock unlocks the lock.