dlock

package
v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 4 Imported by: 0

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.

type Option

type Option func(*Options)

func WithRetryDelay

func WithRetryDelay(d time.Duration) Option

func WithTTL

func WithTTL(d time.Duration) Option

func WithToken

func WithToken(token string) Option

type Options

type Options struct {
	TTL        time.Duration
	RetryDelay time.Duration
	Token      string
}

func NewOptions

func NewOptions(opts ...Option) *Options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL