lock

package
v0.0.0-...-4b98c26 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// LockTimeout is the expiration of a redis lock
	// if any operation is longer than this, it should
	// refresh the lock
	LockTimeout = 20 * time.Second

	// WaitTimeout maximum time to wait before returning control to caller.
	WaitTimeout = 1 * time.Minute

	// WaitRetry time to wait between retries
	WaitRetry = 100 * time.Millisecond
)

Variables

View Source
var (
	// ErrTooManyRetries is the error returned when despite several tries
	// we never managed to get a lock
	ErrTooManyRetries = errors.New("abort after too many failures without getting the lock")
)

Functions

This section is empty.

Types

type ErrorLocker

type ErrorLocker interface {
	Lock() error
	Unlock()
}

An ErrorLocker is a locker which can fail (returns an error)

func LongOperation

func LongOperation(db prefixer.Prefixer, name string) ErrorLocker

LongOperation returns a lock suitable for long operations. It will refresh the lock in redis to avoid its automatic expiration.

type ErrorRWLocker

type ErrorRWLocker interface {
	ErrorLocker
	RLock() error
	RUnlock()
}

ErrorRWLocker is the interface for a RWLock as inspired by RWMutex

func ReadWrite

func ReadWrite(db prefixer.Prefixer, name string) ErrorRWLocker

ReadWrite returns the read/write lock for the given name. By convention, the name should be prefixed by the instance domain on which it applies, then a slash and the package name (ie alice.example.net/vfs).

Jump to

Keyboard shortcuts

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