fallback

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 3 Imported by: 3

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 Builder added in v0.7.0

type Builder[R any] interface {
	failsafe.FailurePolicyBuilder[Builder[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])) Builder[R]

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

Builder 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.

R is the execution result type. This type is not concurrency safe.

func NewBuilderWithError added in v0.7.0

func NewBuilderWithError[R any](err error) Builder[R]

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

func NewBuilderWithFunc added in v0.7.0

func NewBuilderWithFunc[R any](fallbackFunc func(exec failsafe.Execution[R]) (R, error)) Builder[R]

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

func NewBuilderWithResult added in v0.7.0

func NewBuilderWithResult[R any](result R) Builder[R]

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

type Fallback

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

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

R is the execution result type. This type is concurrency safe.

func NewWithError added in v0.7.0

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

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

func NewWithFunc added in v0.7.0

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

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

func NewWithResult added in v0.7.0

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

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

Jump to

Keyboard shortcuts

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