fallback

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package fallback provides a Fallback policy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fallback

type Fallback[R any] interface {
	failsafe.Policy[R]
}

Fallback is a Policy that handles failures using a fallback function, result, or error.

This type is concurrency safe.

func WithError

func WithError[R any](err error) Fallback[R]

WithError returns a Fallback for execution result type R that returns the err when an execution fails.

func WithFunc added in v0.4.0

func WithFunc[R any](fallbackFunc func(exec failsafe.Execution[R]) (R, error)) Fallback[R]

WithFunc returns a Fallback for execution result type R that uses fallbackFunc to handle a failed execution.

func WithResult

func WithResult[R any](result R) Fallback[R]

WithResult returns a Fallback for execution result type R that returns the result when an execution fails.

type FallbackBuilder

type FallbackBuilder[R any] interface {
	failsafe.FailurePolicyBuilder[FallbackBuilder[R], R]

	// OnFallbackExecuted registers the listener to be called when a Fallback has executed. The provided event will contain
	// the execution result and error returned by the Fallback.
	OnFallbackExecuted(listener func(event failsafe.ExecutionDoneEvent[R])) FallbackBuilder[R]

	// Build returns a new Fallback using the builder's configuration.
	Build() Fallback[R]
}

FallbackBuilder builds Fallback instances.

  • By default, any error is considered a failure and will be handled by the policy. You can override this by specifying your own handle conditions. The default error handling condition will only be overridden by another condition that handles errors such as HandleErrors or HandleIf. Specifying a condition that only handles results, such as HandleResult will not replace the default error handling condition.
  • If multiple handle conditions are specified, any condition that matches an execution result or error will trigger policy handling.

This type is not concurrency safe.

func BuilderWithError

func BuilderWithError[R any](err error) FallbackBuilder[R]

BuilderWithError returns a FallbackBuilder for execution result type R which builds Fallbacks that return the error when an execution fails.

func BuilderWithFunc added in v0.4.0

func BuilderWithFunc[R any](fallbackFunc func(exec failsafe.Execution[R]) (R, error)) FallbackBuilder[R]

BuilderWithFunc returns a FallbackBuilder for execution result type R which builds Fallbacks that use the fallbackFn to handle failed executions.

func BuilderWithResult

func BuilderWithResult[R any](result R) FallbackBuilder[R]

BuilderWithResult returns a FallbackBuilder for execution result type R which builds Fallbacks that return the result when an execution fails.

Jump to

Keyboard shortcuts

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