-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_test.go
More file actions
42 lines (35 loc) · 883 Bytes
/
example_test.go
File metadata and controls
42 lines (35 loc) · 883 Bytes
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
package accord_test
import (
"context"
"fmt"
"github.com/bsm/accord"
)
func ExampleClient() {
ctx := context.Background()
// Create a new client
client, err := accord.DialClient(ctx, "10.0.0.1:8432", &accord.ClientOptions{
Namespace: "/custom/namespace",
})
if err != nil {
panic(err)
}
defer client.Close()
// Acquire resource handle.
handle, err := client.Acquire(ctx, "my::resource", nil)
if err == accord.ErrDone {
fmt.Println("Resource has been already marked as done")
return
} else if err == accord.ErrAcquired {
fmt.Println("Resource is currently held by another process")
return
} else if err != nil {
panic(err)
}
defer handle.Discard()
// Yay, we have acquired a handle on the resource, now let's do something!
// ...
// When done, we can mark the resource as done.
if err := handle.Done(ctx, nil); err != nil {
panic(err)
}
}