Documentation
¶
Overview ¶
Package locker provides a mechanism for fine-grained locking.
In contrast to a sync.Mutex, the user must provide a key when locking and unlocking.
If a lock with a given key does not exist when Lock() is called, one is created. Lock references are automatically cleaned up if nothing is waiting for the lock anymore.
Locking can be aborted on context cancellation.
This package is inspired by https://github.com/moby/locker, but uses a buffered channel instead of a sync.Mutex to allow for context cancellation. Even though the standard library does not offer to cancel locking a mutex, golang.org/x/sync/semaphore does for its Acquire() method.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker offers thread-safe locking of entities represented by keys of type string.