Documentation ¶
Index ¶
Constants ¶
const ( // DefaultLockTimeout is the default lock timeout. DefaultLockTimeout = 3 * time.Second // DefaultLockRetryDelay is the default lock retry delay. DefaultLockRetryDelay = 200 * time.Millisecond )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LockOption ¶
type LockOption func(*lockOptions)
LockOption is an option for lock.
func LockWithRetryDelay ¶
func LockWithRetryDelay(retryDelay time.Duration) LockOption
LockWithRetryDelay returns a new LockOption that sets the lock retry delay.
Lock will try to lock on this delay up until the lock timeout.
func LockWithTimeout ¶
func LockWithTimeout(timeout time.Duration) LockOption
LockWithTimeout returns a new LockOption that sets the lock timeout.
Lock returns error if the lock cannot be acquired after this amount of time. If this is set to 0, the lock will never timeout.
type Locker ¶
type Locker interface { // Lock locks a file lock within the root directory of the Locker. // // The given path must be normalized and relative. Lock(ctx context.Context, path string, options ...LockOption) (Unlocker, error) // RLock read-locks a file lock within the root directory of the Locker. // // The given path must be normalized and relative. RLock(ctx context.Context, path string, options ...LockOption) (Unlocker, error) }
Locker provides file locks.
type LockerOption ¶ added in v1.38.0
type LockerOption func(*lockerOptions)
LockerOption is an option for a new Locker.
func LockerWithLockRetryDelay ¶ added in v1.38.0
func LockerWithLockRetryDelay(lockRetryDelay time.Duration) LockerOption
LockerWithLockRetryDelay sets the default lock retry delay for the Locker.
If Lock/RLock is called with LockWithRetryDelay, that will override the default lock retry delay. If this is not set, the default lock retry delay is set to DefaultLockRetryDelay.
func LockerWithLockTimeout ¶ added in v1.38.0
func LockerWithLockTimeout(lockTimeout time.Duration) LockerOption
LockerWithLockTimeout sets the default lock timeout for the Locker.
If Lock/RLock is called with LockWithTimeout, that will override this default timeout. If this is not set, the default lock timeout is set to DefaultLockTimeout.