Documentation
¶
Overview ¶
Package lock defines a unified distributed lock interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotObtained is returned when a lock cannot be acquired. ErrNotObtained = errors.New("lock: not obtained") // ErrNotHeld is returned when unlocking or refreshing a lock that is not held. ErrNotHeld = errors.New("lock: not held") // ErrInvalidTTL is returned when TTL is invalid for the backend. ErrInvalidTTL = errors.New("lock: ttl must be greater than zero") // ErrEmptyKey is returned when the lock key is empty. ErrEmptyKey = errors.New("lock: key must not be empty") )
Functions ¶
func ResolveValue ¶
ResolveValue returns opts.Value or a newly generated token.
Types ¶
type Locker ¶
type Locker interface {
// Lock blocks until the lock is acquired or ctx is done.
Lock(ctx context.Context) error
// TryLock attempts to acquire the lock once without blocking.
TryLock(ctx context.Context) error
// Unlock releases the lock.
Unlock(ctx context.Context) error
// Refresh extends the lock lease/TTL when supported.
Refresh(ctx context.Context) error
}
Locker is a distributed mutual-exclusion lock for a single key.
type Option ¶
type Option func(*Options)
Option mutates Options.
func WithRetryDelay ¶
WithRetryDelay sets the delay between acquire retries.
type Options ¶
type Options struct {
// TTL is the lock lease duration. Required by most backends.
TTL time.Duration
// RetryDelay is the wait between Lock attempts.
RetryDelay time.Duration
// Value is an optional owner token. Generated when empty.
Value string
}
Options holds shared lock configuration.
func ApplyOptions ¶
ApplyOptions builds Options with defaults.
Click to show internal directories.
Click to hide internal directories.