-
Notifications
You must be signed in to change notification settings - Fork 5
/
stl.go
36 lines (30 loc) · 728 Bytes
/
stl.go
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
package stl
import (
"context"
"sync"
)
// A Locker represents an object that can be locked and unlocked.
type Locker interface {
sync.Locker
LockWithContext(context.Context) error
}
// Tx holds the names of shared and exclusive resources to be locked
// atomically.
type Tx interface {
ListShared() []string
ListExclusive() []string
}
// Builder allows to build a Locker or a Tx.
type Builder interface {
Shared(string) Builder
Exclusive(string) Builder
ToLocker(Vault) Locker
ToTx() Tx
}
// Vault defines a resource vault that can lock/unlock resources according to
// the specified transaction.
type Vault interface {
Lock(context.Context, Tx) error
TryLock(context.Context, Tx) (bool, error)
Unlock(Tx)
}