Documentation ¶
Overview ¶
Package lock NOTES
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileLock ¶
type FileLock struct {
// contains filtered or unexported fields
}
FileLock is used to protect the file operation, lock the file by path. !It is essentially a resource lock that cannot be shared between processes or between FileLock instances.
func (*FileLock) TryAcquire ¶
TryAcquire try get the file lock by file path
type Interface ¶
type Interface interface { // Acquire test if the caller can get the resource's lock. // if the caller got the lock, then it will return immediately with ture. // so that it can handle the cache job immediately. Otherwise, the spin // lock will wait until the lock is released by the one who has acquired // the lock. Acquire(resource string) *State // Release the resource lock so that the resource lock is released. // after the resource's lock is released, the other call which is still // waiting for the lock to be released will return immediately. Release(resource string, withLimit bool) }
Interface defines all the supported operations for the resource's lock, which is used to manage the lock of different kind of resources.
type Option ¶
type Option struct { // QPS should >=1 QPS uint // Burst should >= 1, otherwise the limiter // can not work correctly. Burst uint }
Option defines options to initial a resource lock.
type RedisLock ¶
type RedisLock struct {
// contains filtered or unexported fields
}
RedisLock is a distributed resource lock
func NewRedisLock ¶
NewRedisLock initialize a redis lock instance.
func (*RedisLock) Acquire ¶
Acquire caller try to get the resource's lock. if the caller got the lock, then it will return immediately with ture. Otherwise, the caller will wait until the lock is released by the one who has acquired the lock.
func (*RedisLock) Release ¶
Release the resource lock so that the resource lock is released. after the resource's lock is released, the other call which is still waiting for the lock to be released will return immediately.
func (*RedisLock) TryAcquire ¶
TryAcquire caller try to get the resource's lock. Whether or not the caller got the lock, it will return immediately.
type State ¶
type State struct { // Acquired defines if the caller have acquired the lock, // which true means acquired the lock. Acquired bool // WithLimit means the caller does not acquire the lock and // the one who have acquired the lock request the other caller // to consume the resource with limit. WithLimit bool // contains filtered or unexported fields }
State describe the state of the caller to acquire the lock.