throttle

package
v3.65.6 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package throttle implements throttle strategies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OptCloseChan

func OptCloseChan(c <-chan struct{}) func(*Type)

OptCloseChan sets a read-only channel that, if closed, will interrupt a retry throttle early.

func OptMaxExponentPeriod

func OptMaxExponentPeriod(period time.Duration) func(*Type)

OptMaxExponentPeriod sets the maximum period of time that throttles will last when exponentially increasing.

func OptMaxUnthrottledRetries

func OptMaxUnthrottledRetries(n int64) func(*Type)

OptMaxUnthrottledRetries sets the maximum number of consecutive retries that will be attempted before throttling will begin.

func OptThrottlePeriod

func OptThrottlePeriod(period time.Duration) func(*Type)

OptThrottlePeriod sets the static period of time that throttles will last.

Types

type Type

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

Type is a throttle of retries to avoid endless busy loops when a message fails to reach its destination.

func New

func New(options ...func(*Type)) *Type

New creates a new throttle, which permits a static number of consecutive retries before throttling subsequent retries. A success will reset the count of consecutive retries.

func (*Type) ExponentialRetry

func (t *Type) ExponentialRetry() bool

ExponentialRetry is the same as Retry except also sets the throttle period to exponentially increase after each consecutive retry.

func (*Type) ExponentialRetryWithContext

func (t *Type) ExponentialRetryWithContext(ctx context.Context) bool

ExponentialRetryWithContext is the same as RetryWithContext except also sets the throttle period to exponentially increase after each consecutive retry.

func (*Type) Reset

func (t *Type) Reset()

Reset clears the count of consecutive retries and resets the exponential backoff.

func (*Type) Retry

func (t *Type) Retry() bool

Retry indicates that a retry is about to occur and, if appropriate, will block until either the throttle period is over and the retry may be attempted (returning true) or that the close channel has closed (returning false).

func (*Type) RetryWithContext

func (t *Type) RetryWithContext(ctx context.Context) bool

RetryWithContext indicates that a retry is about to occur and, if appropriate, will block until either the throttle period is over and the retry may be attempted (returning true) or that the close channel has closed (returning false), or that the context was cancelled (false).

Jump to

Keyboard shortcuts

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