Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // AlreadyLockedError indicates that the lock is already locked. AlreadyLockedError = errors.New("already locked") // NotLockedError indicates that the lock is not locked when trying to unlock. NotLockedError = errors.New("not locked") )
Functions ¶
This section is empty.
Types ¶
type LeaderElectionCell ¶
type LeaderElectionCell[T comparable] struct { // contains filtered or unexported fields }
func NewLeaderElectionCell ¶
func NewLeaderElectionCell[T comparable](c agency.Agency, key []string, ttl time.Duration) *LeaderElectionCell[T]
func (*LeaderElectionCell[T]) Read ¶
func (l *LeaderElectionCell[T]) Read(ctx context.Context) (T, error)
func (*LeaderElectionCell[T]) Resign ¶
func (l *LeaderElectionCell[T]) Resign(ctx context.Context) error
Resign tries to resign leadership. If error is returned, caller should retry
func (*LeaderElectionCell[T]) Update ¶
func (l *LeaderElectionCell[T]) Update(ctx context.Context, value T) (T, bool, time.Duration, error)
Update checks the current leader cell and if no leader is present it tries to put itself in there. Will return the value currently present, whether we are leader and a duration after which Updated should be called again.
type Lock ¶
type Lock interface { // Lock tries to lock the lock. // If it is not possible to lock, an error is returned. // If the lock is already held by me, an error is returned. Lock(ctx context.Context) error // Unlock tries to unlock the lock. // If it is not possible to unlock, an error is returned. // If the lock is not held by me, an error is returned. Unlock(ctx context.Context) error // IsLocked return true if the lock is held by me. IsLocked() bool }
Lock is an agency backed exclusive lock.
Click to show internal directories.
Click to hide internal directories.