Documentation
¶
Index ¶
Constants ¶
View Source
const ( DefaultTTL = 10 * time.Second DefaultRetryDelay = 50 * time.Millisecond )
Variables ¶
View Source
var ( ErrLockFailed = errors.New("failed to acquire lock") ErrInvalidToken = errors.New("invalid token or lock expired") )
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock interface {
// Unlock releases the lock. It must be idempotent.
Unlock(ctx context.Context) error
// Valid checks if the lock is still valid (non-blocking).
Valid() bool
// Done returns a channel that's closed when the lock is lost or unlocked.
Done() <-chan struct{}
}
Lock represents an acquired distributed lock.
type Locker ¶
type Locker interface {
// Lock acquires the lock, blocking until it succeeds or ctx is canceled.
Lock(ctx context.Context, key string, opts ...Option) (Lock, error)
// TryLock attempts to acquire the lock without blocking.
TryLock(ctx context.Context, key string, opts ...Option) (Lock, bool, error)
}
Locker is the unified interface for distributed locks.
Click to show internal directories.
Click to hide internal directories.