resourcelocks

package
v0.2.396 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package resourcelocks provides a generic mechanism for managing per-resource locks to prevent concurrent modifications on resource-specific operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ResourceLocks

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

ResourceLocks manages per-resource mutexes to prevent concurrent modifications

func New

func New() *ResourceLocks

New creates a new ResourceLocks instance

func (*ResourceLocks) ActiveLocks

func (rl *ResourceLocks) ActiveLocks() int

ActiveLocks returns the number of active locks being managed

func (*ResourceLocks) Clear

func (rl *ResourceLocks) Clear()

Clear removes all locks from the manager This should only be used during shutdown or testing

func (*ResourceLocks) GetLock

func (rl *ResourceLocks) GetLock(resourceID string) *sync.Mutex

GetLock returns a mutex for the given resource ID, creating one if it doesn't exist

func (*ResourceLocks) HasLock

func (rl *ResourceLocks) HasLock(resourceID string) bool

HasLock returns true if a lock exists for the given resource ID

func (*ResourceLocks) ReleaseLock

func (rl *ResourceLocks) ReleaseLock(resourceID string)

ReleaseLock removes the lock for the given resource ID from the internal map This should be called when a resource is removed to prevent memory leaks

func (*ResourceLocks) WithLock

func (rl *ResourceLocks) WithLock(resourceID string, fn func())

WithLock executes the given function while holding the lock for the resource ID

func (*ResourceLocks) WithLockAndError

func (rl *ResourceLocks) WithLockAndError(resourceID string, fn func() error) error

WithLockAndError executes the given function while holding the lock for the resource ID and returns any error from the function

Jump to

Keyboard shortcuts

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