local

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnlockUnknownKey is returned when attempting to unlock a key that is not locked.
	ErrUnlockUnknownKey = fmt.Errorf("local.Locker: unlock of unknown key")

	// ErrRUnlockUnknownKey is returned when attempting to runlock a key that is not locked.
	ErrRUnlockUnknownKey = fmt.Errorf("local.Locker: runlock of unknown key")
)

Functions

func NewLocker

func NewLocker() lock.Locker

NewLocker creates a new local locker.

func NewRWLocker

func NewRWLocker() lock.RWLocker

NewRWLocker creates a new local read-write locker.

Types

type Locker

type Locker struct {
	// contains filtered or unexported fields
}

Locker implements lock.Locker using per-key mutexes. Uses a map of mutexes to provide true per-key locking semantics without the risk of shard collisions. Ref-counting is used to clean up mutexes when they are no longer in use.

func (*Locker) Lock

func (l *Locker) Lock(ctx context.Context, key string, _ time.Duration) error

Lock acquires an exclusive lock. The ttl parameter is ignored.

func (*Locker) TryLock

func (l *Locker) TryLock(ctx context.Context, key string, _ time.Duration) (bool, error)

TryLock attempts to acquire an exclusive lock without blocking.

func (*Locker) Unlock

func (l *Locker) Unlock(ctx context.Context, key string) error

Unlock releases an exclusive lock for the given key.

type RWLocker

type RWLocker struct {
	// contains filtered or unexported fields
}

RWLocker implements lock.RWLocker using per-key RWMutexes.

func (*RWLocker) Lock

func (rw *RWLocker) Lock(ctx context.Context, key string, _ time.Duration) error

Lock acquires an exclusive lock. The ttl parameter is ignored.

func (*RWLocker) RLock

func (rw *RWLocker) RLock(ctx context.Context, key string, _ time.Duration) error

RLock acquires a shared read lock. The ttl parameter is ignored.

func (*RWLocker) RUnlock

func (rw *RWLocker) RUnlock(_ context.Context, key string) error

RUnlock releases a shared read lock for the given key.

func (*RWLocker) TryLock

func (rw *RWLocker) TryLock(ctx context.Context, key string, _ time.Duration) (bool, error)

TryLock attempts to acquire an exclusive lock without blocking.

func (*RWLocker) Unlock

func (rw *RWLocker) Unlock(ctx context.Context, key string) error

Unlock releases an exclusive lock for the given key.

Jump to

Keyboard shortcuts

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