Documentation
¶
Index ¶
- Variables
- type Locker
- type NoopLocker
- func (l NoopLocker) ForceRelease(context.Context) error
- func (l NoopLocker) Get(context.Context) (Owner, error)
- func (l NoopLocker) LockedOwner(context.Context) (Owner, error)
- func (l NoopLocker) Release(context.Context, Owner) error
- func (l NoopLocker) Try(context.Context, func()) error
- func (l NoopLocker) Until(context.Context, time.Duration, func()) error
- type Owner
- type OwnerOption
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Locker ¶
type Locker interface {
// Try tries to get the lock.
// if the lock is locked, it will return an error.
Try(ctx context.Context, fn func()) error
// Until tries to get the lock until the timeout.
// if the lock is locked, it will wait until the lock is released or the timeout is reached.
Until(ctx context.Context, timeout time.Duration, fn func()) error
// Get tries to get the lock.
// if the lock is locked, it will return the owner of the lock or an error.
Get(ctx context.Context) (Owner, error)
// Release releases the locked owner.
// if the owner is not the locked owner, it will return an error.
Release(ctx context.Context, owner Owner) error
// ForceRelease releases the lock forcibly.
ForceRelease(ctx context.Context) error
// LockedOwner returns the owner of the lock.
LockedOwner(ctx context.Context) (Owner, error)
}
type NoopLocker ¶ added in v2.23.0
type NoopLocker struct{}
func (NoopLocker) ForceRelease ¶ added in v2.23.0
func (l NoopLocker) ForceRelease(context.Context) error
func (NoopLocker) LockedOwner ¶ added in v2.23.0
func (l NoopLocker) LockedOwner(context.Context) (Owner, error)
type Owner ¶ added in v2.23.0
type Owner interface {
// Name returns the name of the owner.
Name() string
// Release releases the lock.
Release(ctx context.Context) error
}
func NewOwner ¶ added in v2.23.0
func NewOwner(locker Locker, opts ...OwnerOption) Owner
type OwnerOption ¶ added in v2.23.0
type OwnerOption func(*owner)
func WithOwnerName ¶ added in v2.23.0
func WithOwnerName(name string) OwnerOption
Click to show internal directories.
Click to hide internal directories.