lock

package
v0.0.0-...-e807a05 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyLocked = errors.New("lock: key already locked")
	ErrLockOutsideTx = errors.New("lock: cannot lock outside transaction")
)

Functions

func Hash32

func Hash32(key string) uint32

func Hash64

func Hash64(key string) uint64

func Int32Hash

func Int32Hash(key string) int32

func Int64Hash

func Int64Hash(key string) int64

func Lock

func Lock(ctx context.Context, key *Key) error

Lock locks the given key. If multiple operations lock the same key, it will wait for the previous operation to complete. Lock must be run within a transaction context, panics otherwise.

func TryLock

func TryLock(ctx context.Context, key *Key) error

TryLock locks the given key. If multiple operations lock the same key, only the first will succeed. The rest will fail with the error ErrAlreadyLocked. TryLock must be run within a transaction context, panics otherwise.

Types

type Key

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

func NewIntKey

func NewIntKey(z int64) *Key

func NewIntKeyPair

func NewIntKeyPair(x, y int32) *Key

func NewStrKey

func NewStrKey(z string) *Key

func NewStrKeyPair

func NewStrKeyPair(x, y string) *Key

func (*Key) String

func (k *Key) String() string

type Locker

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

func New

func New(db *sql.DB) *Locker

func (*Locker) Lock

func (l *Locker) Lock(ctx context.Context, key *Key, fn func(context.Context) error) error

func (*Locker) TryLock

func (l *Locker) TryLock(ctx context.Context, key *Key, fn func(context.Context) error) error

Jump to

Keyboard shortcuts

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