stability

package
v0.1.39 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorBreakerServiceUnavailable = errors.New("service unavailable")
)
View Source
var (
	ErrorThrottleTooManyCalls = errors.New("too many calls")
)

Functions

func Breaker

func Breaker[IN, OUT any](fn service.Function[IN, OUT], threshold int) service.Function[IN, OUT]

Breaker wraps a service function with a circuit breaker mechanism. It tracks failures and prevents further calls when a failure threshold is reached.

func Debounce

func Debounce[IN, OUT any](fn service.Function[IN, OUT], duration time.Duration) service.Function[IN, OUT]

Debounce wraps a given function (`fn`) to ensure it is not executed more often than the specified `duration`. If a new call occurs within the debounce duration, the previous call is canceled, and only the latest call proceeds.

func Retry

func Retry[IN, OUT any](fn service.Function[IN, OUT], maxRetries int, delay time.Duration) service.Function[IN, OUT]

Retry wraps a given function (`fn`) to retry its execution upon failure. The function will be retried up to `maxRetries` times with a delay of `delay` between retries. If the context is canceled during retries, it stops immediately and returns the context error.

func Throttle

func Throttle[IN, OUT any](fn service.Function[IN, OUT], maxTokens, refill uint, duration time.Duration) service.Function[IN, OUT]

Throttle adds rate-limiting behavior to the provided function (`fn`). The function can only be called up to `maxTokens` times initially, and then tokens are refilled by `refill` every `duration`. If the limit is exceeded, the function returns `ErrorThrottleTooManyCalls`.

func Timeout

func Timeout[IN, OUT any](fn service.Function[IN, OUT], duration time.Duration) service.Function[IN, OUT]

Timeout wraps a service.Function and enforces a timeout on its execution. If the function does not complete within the specified duration, the context is canceled, and the function returns an error indicating a timeout.

Types

This section is empty.

Jump to

Keyboard shortcuts

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