Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyLock ¶
type KeyLock[K comparable] struct { // contains filtered or unexported fields }
KeyLock is a simple implementation of key based locks with ttl's on them
func NewKeyLock ¶
func NewKeyLock[K comparable]() *KeyLock[K]
func (*KeyLock[K]) Lock ¶
Lock attempts to lock the key for the given duration ttl, blocking until it succeeds or the timeout passes.
Specifically, if the key is currently locked by another caller and cannot be obtained within timeout, Lock returns -1. Otherwise, Lock returns a non-negative handle that can be passed to KeyLock.Lock to unlock the key before the ttl expires. (The lock handle guards against the case where callers attempt to unlock keys that have already expired and have since been re-locked by a different caller.)
Click to show internal directories.
Click to hide internal directories.