Documentation
¶
Overview ¶
Package resourcelocks provides a generic mechanism for managing per-resource locks to prevent concurrent modifications on resource-specific operations.
Index ¶
- type ResourceLocks
- func (rl *ResourceLocks) ActiveLocks() int
- func (rl *ResourceLocks) Clear()
- func (rl *ResourceLocks) GetLock(resourceID string) *sync.Mutex
- func (rl *ResourceLocks) HasLock(resourceID string) bool
- func (rl *ResourceLocks) ReleaseLock(resourceID string)
- func (rl *ResourceLocks) WithLock(resourceID string, fn func())
- func (rl *ResourceLocks) WithLockAndError(resourceID string, fn func() error) error
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 (*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