Documentation
¶
Index ¶
- Variables
- func Breaker[IN any](fn service.Function[IN], threshold int) service.Function[IN]
- func Breaker2[IN, OUT any](fn service.Function2[IN, OUT], threshold int) service.Function2[IN, OUT]
- func Debounce[IN any](fn service.Function[IN], duration time.Duration) service.Function[IN]
- func Debounce2[IN, OUT any](fn service.Function2[IN, OUT], duration time.Duration) service.Function2[IN, OUT]
- func Retry[IN any](fn service.Function[IN], maxRetries int, delay time.Duration) service.Function[IN]
- func Retry2[IN, OUT any](fn service.Function2[IN, OUT], maxRetries int, delay time.Duration) service.Function2[IN, OUT]
- func Throttle[IN any](fn service.Function[IN], maxTokens, refill uint, duration time.Duration) service.Function[IN]
- func Throttle2[IN, OUT any](fn service.Function2[IN, OUT], maxTokens, refill uint, duration time.Duration) service.Function2[IN, OUT]
- func Timeout[IN any](fn service.Function[IN], duration time.Duration) service.Function[IN]
- func Timeout2[IN, OUT any](fn service.Function2[IN, OUT], duration time.Duration) service.Function2[IN, OUT]
Constants ¶
This section is empty.
Variables ¶
var ( ErrorBreakerServiceUnavailable = errors.New("service unavailable") )
var ( // ErrorThrottleTooManyCalls is returned when the rate limit is exceeded. ErrorThrottleTooManyCalls = errors.New("too many calls") )
Functions ¶
func Breaker ¶
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
Breaker2 wraps a Function2 with a circuit breaker mechanism. Prevents calls to `fn` when failures exceed the threshold.
func Debounce ¶
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 ¶
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.