Skip to content

Commit eb87890

Browse files
committed
Re-added ExampleLockFile()
1 parent 62047f5 commit eb87890

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lockfile_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,32 @@ import (
44
"fmt"
55
"io/ioutil"
66
"math/rand"
7+
"os"
78
"path/filepath"
89
"strconv"
910
"testing"
1011
)
1112

13+
func ExampleLockfile() {
14+
lock, err := New(filepath.Join(os.TempDir(), "lock.me.now.lck"))
15+
if err != nil {
16+
fmt.Printf("Cannot init lock. reason: %v\n", err)
17+
panic(err)
18+
}
19+
err = lock.TryLock()
20+
21+
// Error handling is essential, as we only try to get the lock.
22+
if err != nil {
23+
fmt.Printf("Cannot lock \"%v\", reason: %v\n", lock, err)
24+
panic(err)
25+
}
26+
27+
defer lock.Unlock()
28+
29+
fmt.Println("Do stuff under lock")
30+
// Output: Do stuff under lock
31+
}
32+
1233
func TestLock(t *testing.T) {
1334
path, err := filepath.Abs("test_lockfile.pid")
1435
if err != nil {

0 commit comments

Comments
 (0)