locking

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 5 Imported by: 0

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 NewInMemLocker

func NewInMemLocker() *InMemLocker

NewInMemLocker creates a new InMemLocker.

func (*InMemLocker) Acquire

func (l *InMemLocker) Acquire(ctx context.Context, key string, ttl time.Duration, timeout time.Duration) (bool, error)

func (*InMemLocker) Close

func (l *InMemLocker) Close() error

func (*InMemLocker) Release

func (l *InMemLocker) Release(ctx context.Context, key string) 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.

type LockerProvider added in v0.2.0

type LockerProvider func(url string, bucketOrPrefix string) (Locker, error)

func GetLocker added in v0.2.0

func GetLocker(name string) (LockerProvider, bool)

Jump to

Keyboard shortcuts

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