Documentation
¶
Index ¶
Constants ¶
View Source
const LockOwnerKey contextKey = "lock_owner"
Variables ¶
View Source
var ( ErrLockAcquisitionTimeout = errors.New("lock acquisition timed out") ErrLockNotHeld = errors.New("lock not held") )
Functions ¶
func RegisterLocker ¶ added in v0.2.0
func RegisterLocker(name string, provider LockerProvider)
Types ¶
type InMemLocker ¶
type InMemLocker struct {
// contains filtered or unexported fields
}
InMemLocker is a simple thread-safe in-memory locker.
func (*InMemLocker) Close ¶
func (l *InMemLocker) Close() error
type Locker ¶
type Locker interface {
// Acquire attempts to acquire a lock for the given key.
// ttl is the maximum time the lock can be held before auto-expiring.
// timeout is the maximum time to wait for the lock to become available.
Acquire(ctx context.Context, key string, ttl time.Duration, timeout time.Duration) (bool, error)
// Release releases the lock for the given key.
Release(ctx context.Context, key string) error
// Close shuts down the locker.
Close() error
}
Locker defines the interface for distributed locking.
Click to show internal directories.
Click to hide internal directories.