lock

package
v0.0.0-...-b1203ac Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: BSD-3-Clause Imports: 7 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: lock must be carried out in transaction")
)

Functions

func Hash32

func Hash32(key string) uint32

func Hash64

func Hash64(key string) uint64

func IntHash32

func IntHash32(key string) int32

func IntHash64

func IntHash64(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.

func Uint32ToInt32

func Uint32ToInt32(u32 uint32) int32

func Uint64ToInt64

func Uint64ToInt64(u64 uint64) int64

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) (func(), error)

func (*Locker) TryLock

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

Jump to

Keyboard shortcuts

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