lock

package
v0.13.0-clearcare-1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Canceled = errors.New("lock canceled by another process")

Canceled is returned when another process cancels this lock.

View Source
var ErrLockTimeout = errors.New("timed out waiting for lock")

ErrLockTimeout is returned when obtaining the lock times out.

Functions

This section is empty.

Types

type AdvisoryLock

type AdvisoryLock struct {
	// This will be added as a comment string to the query to obtain the
	// lock, which can be useful in debugging.
	Context string

	// An optional timeout for obtaining the lock. The zero value is no
	// timeout.
	LockTimeout time.Duration
	// contains filtered or unexported fields
}

AdvisoryLock wraps PostgresSQL advisory locks to act like a sync.Locker.

func NewAdvisoryLock

func NewAdvisoryLock(db *sql.DB, key uint32) (*AdvisoryLock, error)

NewAdvisoryLock opens a new transaction and returns the AdvisoryLock.

func (*AdvisoryLock) CancelPending

func (l *AdvisoryLock) CancelPending() error

CancelPending cancels any pending advisory locks (those that are not yet granted) for this advisory lock key.

This can be useful in situations where you only want a maximum of 1 process waiting to obtain the lock at any time.

func (*AdvisoryLock) Lock

func (l *AdvisoryLock) Lock() error

Lock obtains the advisory lock.

func (*AdvisoryLock) Locker

func (l *AdvisoryLock) Locker() sync.Locker

Locker returns a sync.Locker compatible version of this AdvisoryLock.

func (*AdvisoryLock) Unlock

func (l *AdvisoryLock) Unlock() error

Unlock releases the advisory lock.

Jump to

Keyboard shortcuts

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