Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCASConflict is returned when a CAS operation fails. ErrCASConflict = errors.New("CAS conflict") // ErrCASConflictTimeout is returned when a CAS operation fails // even after retrying. ErrCASConflictTimeout = errors.New("CAS conflict timeout") )
var ( // ErrMRSWConflict is returned when a MultiRSW operation fails. ErrMRSWConflict = errors.New("MRSW conflict") )
Functions ¶
This section is empty.
Types ¶
type AtomicBool ¶
type AtomicBool struct {
// contains filtered or unexported fields
}
AtomicBool is a boolean with atomic operations.
func NewAtomicBool ¶
func NewAtomicBool() *AtomicBool
NewAtomicBool returns a new AtomicBool initialized to false.
func (*AtomicBool) Is ¶
func (b *AtomicBool) Is() bool
Is returns true if the AtomicBool is true, false otherwise.
type AtomicString ¶
type AtomicString struct {
// contains filtered or unexported fields
}
AtomicString is a string with atomic operations.
func NewAtomicString ¶
func NewAtomicString() *AtomicString
NewAtomicString returns a new AtomicString.
func (*AtomicString) Store ¶
func (s *AtomicString) Store(newString string)
Store stores a new string.
type AtomicTime ¶
type AtomicTime struct {
// contains filtered or unexported fields
}
AtomicTime is a time.Time with atomic operations.
func (*AtomicTime) Add ¶
func (t *AtomicTime) Add(d time.Duration)
Add adds a duration to the stored time.
func (*AtomicTime) IsZero ¶
func (t *AtomicTime) IsZero() bool
IsZero returns true if the stored time is zero, false otherwise.
func (*AtomicTime) Sub ¶
func (t *AtomicTime) Sub(tt *AtomicTime) time.Duration
Sub return the difference between the stored time and the given time.
type CheckAndSet ¶
type CheckAndSet struct {
// contains filtered or unexported fields
}
CheckAndSet is a simple concurrency control mechanism that allows only one goroutine to execute a critical section at a time.
func NewCheckAndSet ¶
func NewCheckAndSet() *CheckAndSet
NewCheckAndSet creates a new CheckAndSet instance.
func (*CheckAndSet) Begin ¶
func (c *CheckAndSet) Begin(owner string) error
Begin attempts to enter the critical section. If another goroutine is already in the critical section, Begin returns an error of type ErrCASConflict.
func (*CheckAndSet) BeginWithRetry ¶
func (c *CheckAndSet) BeginWithRetry(owner string, timeout, retryInterval time.Duration) error
BeginWithRetry will attempt to enter the critical section, retrying if necessary.
func (*CheckAndSet) Owner ¶
func (c *CheckAndSet) Owner() string
Owner returns the current owner of the critical section.
func (*CheckAndSet) Stats ¶
func (c *CheckAndSet) Stats() map[string]interface{}
Stats returns diagnostic information about the current state of the CheckAndSet instance.
type MultiRSW ¶
type MultiRSW struct {
// contains filtered or unexported fields
}
MultiRSW is a simple concurrency control mechanism that allows multiple readers or a single writer to execute a critical section at a time.
func (*MultiRSW) BeginWrite ¶
BeginWrite attempts to enter the critical section as a writer.
func (*MultiRSW) EndRead ¶
func (r *MultiRSW) EndRead()
EndRead exits the critical section as a reader.
func (*MultiRSW) EndWrite ¶
func (r *MultiRSW) EndWrite()
EndWrite exits the critical section as a writer.
func (*MultiRSW) UpgradeToWriter ¶
UpgradeToWriter attempts to upgrade a read lock to a write lock. The client must be the only reader in order to upgrade, and must already be in a read lock.
type Ordered ¶
type Ordered interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
~float32 | ~float64 | ~string
}
Ordered is a type that can be compared.
type PollTrue ¶
type PollTrue struct {
// contains filtered or unexported fields
}
PollTrue is a utility for polling a function until it returns true or a timeout is reached.
func NewPollTrue ¶
NewPollTrue creates a new PollTrue instance.
type ReadyChannels ¶
type ReadyChannels struct {
// contains filtered or unexported fields
}
ReadyChannels is a collection of channels that can be used to signal readiness.
func NewReadyChannels ¶
func NewReadyChannels() *ReadyChannels
NewReadyChannels returns a new ReadyChannels.
func (*ReadyChannels) Ready ¶
func (r *ReadyChannels) Ready() bool
Ready returns true if all registered channels have been closed.
func (*ReadyChannels) Register ¶
func (r *ReadyChannels) Register(ch <-chan struct{})
Register registers a channel with the ReadyChannels. Until the given channel is closed, the ReadyChannels is not considered ready.
type ReadyTarget ¶
type ReadyTarget[T Ordered] struct { // contains filtered or unexported fields }
ReadyTarget is a mechanism whereby a target can be signalled as reached.
func NewReadyTarget ¶
func NewReadyTarget[T Ordered]() *ReadyTarget[T]
NewReadyTarget returns a new ReadyTarget.
func (*ReadyTarget[T]) Len ¶
func (r *ReadyTarget[T]) Len() int
Len returns the number of subscribers.
func (*ReadyTarget[T]) Reset ¶
func (r *ReadyTarget[T]) Reset()
Reset resets the ReadyTarget back to the initial state, removing any subscribers.
func (*ReadyTarget[T]) Signal ¶
func (r *ReadyTarget[T]) Signal(index T)
Signal informs the ReadyTarget that the given target has been reached. If the target is less than or equal to the current target, then the index is ignored.
func (*ReadyTarget[T]) Subscribe ¶
func (r *ReadyTarget[T]) Subscribe(target T) <-chan struct{}
Subscribe returns a channel that will be closed when the target is reached. If the target has already been a reached the channel will be returned in a closed state.
func (*ReadyTarget[T]) Unsubscribe ¶
func (r *ReadyTarget[T]) Unsubscribe(ch <-chan struct{})
Unsubscribe removes the subscription for the given target.
type Subscriber ¶
type Subscriber[T Ordered] struct { // contains filtered or unexported fields }
Subscriber is a subscription to notifications for a target being reached.