postgres

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool implements a distlock.Locker backed by a pgxpool.Pool.

func NewPool

func NewPool(pool *pgxpool.Pool, retry time.Duration) *Pool

NewPool returns a lock struct backed by the provided connection pool.

The returned lock can be reused

func (*Pool) Lock

func (p *Pool) Lock(ctx context.Context, key string) error

Lock attempts to take the lock identified by 'key', blocking and retrying on the period specified at creation until successful or the provided context is cancelled.

func (*Pool) TryLock

func (p *Pool) TryLock(ctx context.Context, key string) (bool, error)

TryLock is a nonblocking attempt at taking the lock identified by 'key'.

If successful, the duration of the lock is tied to the provided context; that is, if the context is canceled the lock will automatically be released.

func (*Pool) Unlock

func (p *Pool) Unlock() error

Unlock releases a held lock and resets the lock for future use.

Jump to

Keyboard shortcuts

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