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) 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.
Click to show internal directories.
Click to hide internal directories.