stability

package
v0.1.53 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 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 ensures that fn(...) is ultimately called only once if multiple calls arrive within the given duration. Each call waits until that one call finishes, returning the same result/error.

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