synckit

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 8 Imported by: 0

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) Attempt

func (b *Backoff) Attempt() int

Attempt returns the current attempt counter value.

func (*Backoff) Copy

func (b *Backoff) Copy() *Backoff

Copy returns a backoff with equals constraints as the original

func (*Backoff) Duration

func (b *Backoff) Duration() time.Duration

Duration returns the duration for the current attempt before incrementing the attempt counter. See ForAttempt.

func (*Backoff) ForAttempt

func (b *Backoff) ForAttempt(attempt int) time.Duration

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.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset restarts the current attempt counter at zero.

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 NewOccasion(deadline time.Time) Occasion

func NewOccasionAfter

func NewOccasionAfter(d time.Duration) Occasion

type RWLocker

type RWLocker interface {
	sync.Locker
	RLock()
	RUnlock()
}

func DummyLocker

func DummyLocker() RWLocker

type Semaphore

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

func NewSemaphore

func NewSemaphore(limit int) Semaphore

func (Semaphore) Close

func (v Semaphore) Close()

func (Semaphore) IsFull

func (v Semaphore) IsFull() bool

func (Semaphore) Lock

func (v Semaphore) Lock()

func (Semaphore) LockExt

func (v Semaphore) LockExt(d time.Duration, done <-chan struct{}) bool

func (Semaphore) LockTimeout

func (v Semaphore) LockTimeout(d time.Duration) bool

func (Semaphore) TryLock

func (v Semaphore) TryLock() bool

func (Semaphore) Unlock

func (v Semaphore) Unlock()

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 SyncFunc

type SyncFunc func(interface{})

type SyncFuncList

type SyncFuncList []SyncFunc

type SyncQueue

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

func NewNoSyncQueue

func NewNoSyncQueue() SyncQueue

func NewSignalCondQueue

func NewSignalCondQueue(signal *sync.Cond) SyncQueue

func NewSignalFuncQueue

func NewSignalFuncQueue(locker sync.Locker, signalFn func()) SyncQueue

func NewSyncQueue

func NewSyncQueue(locker sync.Locker) SyncQueue

func (*SyncQueue) Add

func (p *SyncQueue) Add(fn SyncFunc)

func (*SyncQueue) AddAll

func (p *SyncQueue) AddAll(list SyncFuncList)

func (*SyncQueue) Flush

func (p *SyncQueue) Flush() SyncFuncList

func (*SyncQueue) IsZero

func (p *SyncQueue) IsZero() bool

func (*SyncQueue) Locker

func (p *SyncQueue) Locker() sync.Locker

type TimerHolder

type TimerHolder interface {
	Channel() <-chan time.Time
	Stop()
}

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()

Jump to

Keyboard shortcuts

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