Documentation ¶
Overview ¶
Package backoff provides an exponential-backoff implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SafeClose ¶
func SafeClose(c ClosableSignalChannel) (err error)
Types ¶
type Backoff ¶
type Backoff struct { // Factor is the multiplying factor for each increment step Factor float64 // Jitter eases contention by randomizing backoff steps Jitter bool // Min and Max are the minimum and maximum values of the counter Min, Max time.Duration // contains filtered or unexported fields }
Backoff is a time.Duration counter, starting at Min. After every call to the Duration method the current timing is multiplied by Factor, but it never exceeds Max.
Backoff is not generally concurrent-safe, but the ForAttempt method can be used concurrently.
func (*Backoff) Duration ¶
Duration returns the duration for the current attempt before incrementing the attempt counter. See ForAttempt.
func (*Backoff) ForAttempt ¶
ForAttempt returns the duration for a specific attempt. This is useful if you have a large number of independent Backoffs, but don't want use unnecessary memory storing the Backoff parameters per Backoff. The first attempt should be 0.
ForAttempt is concurrent-safe.
type ChainedCancel ¶
type ChainedCancel struct {
// contains filtered or unexported fields
}
func NewChainedCancel ¶
func NewChainedCancel() *ChainedCancel
func (*ChainedCancel) Cancel ¶
func (p *ChainedCancel) Cancel()
func (*ChainedCancel) IsCancelled ¶
func (p *ChainedCancel) IsCancelled() bool
func (*ChainedCancel) SetChain ¶
func (p *ChainedCancel) SetChain(chain context.CancelFunc)
SetChain sets a chained function once. The chained function can only be set once to a non-null value, further calls will panic. But if the chained function was not set, the SetChain(nil) can be called multiple times. The chained function is guaranteed to be called only once, it will also be called on set when IsCancelled is already true.
type ClosableSignalChannel ¶
type ClosableSignalChannel = chan struct{}
type Occasion ¶
type Occasion interface { Deadline() time.Time NewTimer() TimerHolder NewFunc(fn func()) TimerHolder IsExpired() bool }
func EverOccasion ¶
func EverOccasion() Occasion
func NeverOccasion ¶
func NeverOccasion() Occasion
func NewOccasion ¶
func NewOccasionAfter ¶
type RWLocker ¶
func DummyLocker ¶
func DummyLocker() RWLocker
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
func NewSemaphore ¶
type SignalChannel ¶
type SignalChannel = <-chan struct{}
func ClosedChannel ¶
func ClosedChannel() SignalChannel
type SignalVersion ¶
type SignalVersion struct {
// contains filtered or unexported fields
}
func NewNeverSignal ¶
func NewNeverSignal() *SignalVersion
func (*SignalVersion) Channel ¶
func (p *SignalVersion) Channel() <-chan struct{}
func (*SignalVersion) ChannelIf ¶
func (p *SignalVersion) ChannelIf(choice bool, def <-chan struct{}) <-chan struct{}
func (*SignalVersion) HasSignal ¶
func (p *SignalVersion) HasSignal() bool
func (*SignalVersion) Wait ¶
func (p *SignalVersion) Wait()
type SyncFuncList ¶
type SyncFuncList []SyncFunc
type SyncQueue ¶
type SyncQueue struct {
// contains filtered or unexported fields
}
func NewNoSyncQueue ¶
func NewNoSyncQueue() SyncQueue
func NewSignalCondQueue ¶
func NewSignalFuncQueue ¶
func NewSyncQueue ¶
func (*SyncQueue) AddAll ¶
func (p *SyncQueue) AddAll(list SyncFuncList)
func (*SyncQueue) Flush ¶
func (p *SyncQueue) Flush() SyncFuncList
type TimerHolder ¶
func Never ¶
func Never() TimerHolder
func NewTimer ¶
func NewTimer(d time.Duration) TimerHolder
func NewTimerWithFunc ¶
func NewTimerWithFunc(d time.Duration, fn func()) TimerHolder
type VersionedSignal ¶
type VersionedSignal struct {
// contains filtered or unexported fields
}
func NewVersionedSignal ¶
func NewVersionedSignal() VersionedSignal
func (*VersionedSignal) BroadcastAndMark ¶
func (p *VersionedSignal) BroadcastAndMark() *SignalVersion
func (*VersionedSignal) Mark ¶
func (p *VersionedSignal) Mark() *SignalVersion
func (*VersionedSignal) NextBroadcast ¶
func (p *VersionedSignal) NextBroadcast()