lock

package
v0.15.5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLockExists is returned from Lock() when the lock is already taken.
	ErrLockExists = errors.New("lock exists")
	// ErrNoLockExists is returned from Unlock() when the lock does not exist.
	ErrNoLockExists = errors.New("no lock exists")
)

Functions

func NewMiddleware

func NewMiddleware(l Lock) eh.CommandHandlerMiddleware

NewMiddleware returns a new lock middle ware using a provided lock implementation. Useful for handling only one command per aggregate ID at a time.

Types

type LocalLock

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

LocalLock is a Lock implemention using local locking only. Not suitable for use in distributed environments.

func NewLocalLock

func NewLocalLock() *LocalLock

NewLocalLock creates a new LocalLock.

func (*LocalLock) Lock

func (l *LocalLock) Lock(id string) error

Lock implements the Lock method of the Lock interface.

func (*LocalLock) Unlock

func (l *LocalLock) Unlock(id string) error

Unlock implements the Unlock method of the Lock interface.

type Lock

type Lock interface {
	// Lock sets a lock for the ID. Returns ErrLockExists if the lock is already
	// taken or another error if it was not possible to get the lock.
	Lock(id string) error
	// Unlock releases the lock for the ID. Returns ErrNoLockExists if there is
	// no lock for the ID or another error if it was not possible to unlock.
	Unlock(id string) error
}

Lock is a locker of IDs.

Jump to

Keyboard shortcuts

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