stability

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorBreakerServiceUnavailable indicates the circuit breaker is open.
	ErrorBreakerServiceUnavailable = errors.New("service unavailable")
)
View Source
var (
	// ErrorThrottleTooManyCalls is returned when the rate limit is exceeded.
	ErrorThrottleTooManyCalls = errors.New("too many calls")
)

Functions

func Breaker

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

Breaker wraps a service function with a circuit breaker mechanism. Prevents calls to `fn` when failures exceed the threshold.

func Breaker2 added in v0.1.4

func Breaker2[IN, OUT any](fn service.Function2[IN, OUT], threshold int) service.Function2[IN, OUT]

Breaker2 wraps a Function2 with a circuit breaker mechanism. Prevents calls to `fn` when failures exceed the threshold.

func Debounce

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

Debounce delays the invocation of the provided function until a specified duration has passed since its last invocation.

func Debounce2 added in v0.1.4

func Debounce2[IN, OUT any](fn service.Function2[IN, OUT], duration time.Duration) service.Function2[IN, OUT]

Debounce2 delays the invocation of a function with input and output until a specified duration has passed since its last invocation.

func Retry

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

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 Retry2 added in v0.1.4

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

Retry2 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 any](fn service.Function[IN], maxTokens, refill uint, duration time.Duration) service.Function[IN]

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 Throttle2 added in v0.1.4

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

Throttle2 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 any](fn service.Function[IN], duration time.Duration) service.Function[IN]

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.

func Timeout2 added in v0.1.4

func Timeout2[IN, OUT any](fn service.Function2[IN, OUT], duration time.Duration) service.Function2[IN, OUT]

Timeout2 wraps a service.Function2 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