conc

package
v0.29.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyPoisoned = fmt.Errorf("lock was already poisoned")

ErrAlreadyPoisoned is returned if you try to lock a lock which was already poisoned

View Source
var ErrNotOwned = errors.New("the lock was not (no longer) owned by you")

you tried to release a lock that you (no longer) own. Make sure you are not releasing a lock twice and are releasing a lock in a timely manner.

View Source
var ErrOwnedLock = errors.New("lock owned")

you failed to acquire a lock before the operation timed out

Functions

func IsLeaderElectionFatalError

func IsLeaderElectionFatalError(err error) bool

func IsLeaderElectionTransientError

func IsLeaderElectionTransientError(err error) bool

Types

type DistributedLock

type DistributedLock interface {
	// Extend your lease of the lock to at least the given duration
	// (so if your lock has 3 seconds remaining and you give a
	// duration of 5 seconds, your lock is now locked at least until
	// now + 5 seconds).
	// Aborts the operation if the context gets canceled before
	// the operation finishes.
	// Might fail with ErrNotOwned if you are no longer the
	// owner of the lock.
	Renew(ctx context.Context, lockTime time.Duration) error
	// Release a lock. Might fail with ErrNotOwned if you are
	// releasing a lock too late.
	Release() error
}

type DistributedLockProvider

type DistributedLockProvider interface {
	// Acquire a lock for a duration (given e.g. in a constructor). Aborts the operation if the
	// context is canceled before the lock can be acquired.
	Acquire(ctx context.Context, resource string) (DistributedLock, error)
}

type DistributedLockSettings

type DistributedLockSettings struct {
	cfg.AppId
	Backoff         exec.BackoffSettings
	DefaultLockTime time.Duration
	Domain          string
}

type KeyLock

type KeyLock interface {
	// Lock based on the given key, returns an UnlockFunc when called it unlocks the underlying key and
	// releases the resources.
	Lock(key any) UnlockFunc
}

func NewKeyLock

func NewKeyLock() KeyLock

type Lazy

type Lazy[T any, ARG any] interface {
	Get(arg ARG) (T, error)
}

Lazy provides a thread-safe way of creating a resource on-demand, allowing you to provide needed data with a parameter

func NewLazy

func NewLazy[T any, ARG any](init func(arg ARG) (T, error)) Lazy[T, ARG]

NewLazy creates a new, empty Lazy with the given init function.

type LeaderElectionFatalError

type LeaderElectionFatalError struct {
	// contains filtered or unexported fields
}

func NewLeaderElectionFatalError

func NewLeaderElectionFatalError(err error) LeaderElectionFatalError

func (LeaderElectionFatalError) Error

func (e LeaderElectionFatalError) Error() string

func (LeaderElectionFatalError) Unwrap

func (e LeaderElectionFatalError) Unwrap() error

type LeaderElectionTransientError

type LeaderElectionTransientError struct {
	// contains filtered or unexported fields
}

func NewLeaderElectionTransientError

func NewLeaderElectionTransientError(err error) LeaderElectionTransientError

func (LeaderElectionTransientError) Error

func (LeaderElectionTransientError) Unwrap

type PoisonedLock

type PoisonedLock interface {
	// MustLock is like TryLock, but panics if an error is returned by TryLock
	MustLock()
	// TryLock will acquire the lock if it has not yet been poisoned. Otherwise, an error is returned.
	TryLock() error
	// Unlock will release the lock again. You need to hold the lock before calling Unlock.
	Unlock()
	// Poison will acquire the lock, check if is not poisoned, and the poison the lock (so you can only poison a lock once).
	// After a lock has been poisoned, you can not lock it again. Instead, ErrAlreadyPoisoned will be returned by TryLock.
	Poison() error
	// PoisonIf will acquire the lock and run the supplied function. If the function returns true (regardless of any error),
	// the lock is poisoned, otherwise it is only unlocked.
	PoisonIf(func() (bool, error)) error
}

A PoisonedLock is similar to a sync.Mutex, but once you Poison it, any attempt to Lock it will fail. Thus, you can implement something which is available for some time and at some point no longer is available (because it was closed or released and is not automatically reopened, etc.)

func NewPoisonedLock

func NewPoisonedLock() PoisonedLock

NewPoisonedLock creates a new lock which can be poisoned. It is initially unlocked and not poisoned.

type SignalOnce

type SignalOnce interface {
	// Signal causes the channel returned by Channel to be closed.
	// All go routines waiting on that channel thus immediately get a value.
	// Can be called more than once.
	Signal()
	// Channel returns a channel you can read on to wait for Signal to be called.
	Channel() chan struct{}
	// Signaled returns true after Signal has been called at least once.
	Signaled() bool
}

func NewSignalOnce

func NewSignalOnce() SignalOnce

type UnlockFunc

type UnlockFunc func()

Directories

Path Synopsis
ddb

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL