lock

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemoryLocker

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

InMemoryLocker is an implementation of the Locker interface that uses an in-memory mutex map.

func (*InMemoryLocker) WithLock

func (l *InMemoryLocker) WithLock(key string, f func() error) error

WithLock acquires a lock for the given key, executes the function, and releases the lock.

type Locker

type Locker interface {
	// WithLock acquires a lock for the given key, executes the provided function,
	// and guarantees the lock is released afterward.
	WithLock(key string, f func() error) error
}

Locker defines the interface for a distributed, blocking locking mechanism.

func NewInMemoryLocker

func NewInMemoryLocker() Locker

NewInMemoryLocker creates a new instance of InMemoryLocker.

func NewPostgresLocker

func NewPostgresLocker(db *gorm.DB) Locker

NewPostgresLocker creates a new instance of PostgresLocker.

type PostgresLocker

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

PostgresLocker is an implementation of the Locker interface that uses PostgreSQL advisory locks.

func (*PostgresLocker) WithLock

func (p *PostgresLocker) WithLock(key string, f func() error) error

WithLock acquires a transaction-level advisory lock, executes the function, and releases the lock upon transaction commit or rollback.

Jump to

Keyboard shortcuts

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