vault

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package vault solves the handling of mutexes.

Index

Constants

View Source
const (
	Single QueueType = "single"
	Multi  QueueType = "multi"

	LOCKED   lockState = true
	UNLOCKED lockState = false
)

Variables

View Source
var (
	ErrUnnecessaryAcquire = errors.New(
		"client tried to acquire a lock that it already had acquired",
	)
	ErrUnnecessaryRelease = errors.New(
		"client tried to release a lock that had not been acquired",
	)
	ErrBadManners = errors.New(
		"client tried to release lock that it did not own",
	)
)

Functions

This section is empty.

Types

type Mock added in v0.5.2

type Mock struct {
	AcquireCount int
	ReleaseCount int
	CleanupCount int
	// contains filtered or unexported fields
}

func NewMock added in v0.5.2

func NewMock() *Mock

func (*Mock) Acquire added in v0.5.2

func (v *Mock) Acquire(lockTag string, client string, callback func(error) error)

Acquire implements Vault.

func (*Mock) AwaitAcquire added in v0.5.2

func (v *Mock) AwaitAcquire(lockTag string) error

func (*Mock) AwaitRelease added in v0.5.2

func (v *Mock) AwaitRelease(lockTag string) error

func (*Mock) Cleanup added in v0.5.2

func (v *Mock) Cleanup(locktag string, client string)

Cleanup implements Vault.

func (*Mock) EnableAwaits added in v0.5.2

func (v *Mock) EnableAwaits()

func (*Mock) Release added in v0.5.2

func (v *Mock) Release(lockTag string, client string, callback func(error) error)

Release implements Vault.

type Opts added in v0.5.2

type Opts struct {
	// Single queue mode should only be used for testing.
	QueueType

	// Only for multi-mode queues, determines the number of
	// supporting Go-routines able to handle work given to the
	// queueing layer.
	QueueConcurrency int

	// Sets the capacity of the underlying queue(s), the max amount
	// of buffered work for a queue. In a multi queue setting, the
	// capacity indicates the buffer size per queue.
	QueueCapacity int
}

type QueueType

type QueueType string

type Vault

type Vault interface {
	// Lock tag is a string identifying the lock to acquire, client the requesting party,
	// and the callback a function which will be called to either confirm acquisition or
	// including an error in case the client is misbehaving. The callback may return an
	// error in case feedback handling encounters an error.
	Acquire(lockTag, client string, callback func(error) error)
	Release(lockTag, client string, callback func(error) error)
	Cleanup(locktag, client string)
}

The Vault interface specifies high level functions to implement in order to handle the acquisition and release of mutexes.

func New added in v0.5.2

func New(options *Opts) Vault

Directories

Path Synopsis
Package queue implements a way for the vault to ensure single-threaded handling of mutexes.
Package queue implements a way for the vault to ensure single-threaded handling of mutexes.

Jump to

Keyboard shortcuts

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