locker

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Namespace string = "_Locker"
	TTL              = time.Second * 30
)

Variables

View Source
var (
	ErrStatusBusy = errors.New("status busy")
)

Functions

func MutexLock

func MutexLock(lockID string, ttl int64, backend Backend) error

func MutexTryLock

func MutexTryLock(lockID string, ttl int64, deadline int64, backend Backend) bool

func MutexUnlock

func MutexUnlock(lockID string, backend Backend) error

func MutexWithCustomID

func MutexWithCustomID(id string) func(mutex *Mutex)

func MutexWithTTL

func MutexWithTTL(deadline time.Duration) func(mutex *Mutex)

Types

type Backend

type Backend interface {
	Get(key []byte) (*store.Value, error)
	TrySetWithTTL(key, value []byte, ttl uint32) error
	Del(key []byte) error
	Watch(key []byte) (notify store.WatcherNotify, err error)
}

type Mutex

type Mutex struct {
	TTL    time.Duration
	LockID string
	// contains filtered or unexported fields
}

func NewMutex

func NewMutex(s Backend, options ...MutexOption) (*Mutex, error)

func (*Mutex) Lock

func (l *Mutex) Lock() error

func (*Mutex) TryLock

func (l *Mutex) TryLock(deadline time.Duration) bool

TryLock tries to lock m and reports whether it succeeded.

Note that if the mutex is not released before reaching the deadline it will wait until it is released, and it maybe not succeed

func (*Mutex) Type

func (l *Mutex) Type() string

func (*Mutex) Unlock

func (l *Mutex) Unlock() error

type MutexOption

type MutexOption func(*Mutex)

Jump to

Keyboard shortcuts

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