hooks

package
v0.0.0-...-788b660 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2025 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCircuitOpen = errors.New("circuit breaker is open")

ErrCircuitOpen is returned when an operation is attempted while the circuit breaker is in the open state.

Functions

This section is empty.

Types

type CircuitBreaker

type CircuitBreaker interface {
	Open() bool
	Fail()
	Success()
}

CircuitBreaker defines the interface for the Circuit Breaker pattern.

type CircuitBreakerHooks

type CircuitBreakerHooks[T any] struct {
	// contains filtered or unexported fields
}

CircuitBreakerHooks checks whether the circuit breaker is open before sending. If so, it returns ErrCircuitOpen, otherwise the corresponding method of the inner Hooks is called.

func NewCircuitBreakerHooks

func NewCircuitBreakerHooks[T any](cb CircuitBreaker,
	hooks Hooks[T]) CircuitBreakerHooks[T]

NewCircuitBreakerHooks creates a new CircuitBreakerHooks.

func (CircuitBreakerHooks[T]) BeforeSend

func (h CircuitBreakerHooks[T]) BeforeSend(ctx context.Context, cmd core.Cmd[T]) (
	context.Context, error)

func (CircuitBreakerHooks[T]) OnError

func (h CircuitBreakerHooks[T]) OnError(ctx context.Context, sentCmd SentCmd[T],
	err error)

func (CircuitBreakerHooks[T]) OnResult

func (h CircuitBreakerHooks[T]) OnResult(ctx context.Context, sentCmd SentCmd[T],
	recvResult ReceivedResult, err error)

func (CircuitBreakerHooks[T]) OnTimeout

func (h CircuitBreakerHooks[T]) OnTimeout(ctx context.Context, sentCmd SentCmd[T],
	err error)

type CircuitBreakerHooksFactory

type CircuitBreakerHooksFactory[T any] struct {
	// contains filtered or unexported fields
}

CircuitBreakerHooksFactory can be used to create hooks that incorporate circuit breaker logic during the command sending process.

func NewCircuitBreakerHooksFactory

func NewCircuitBreakerHooksFactory[T any](cb CircuitBreaker,
	factory HooksFactory[T]) CircuitBreakerHooksFactory[T]

NewCircuitBreakerHooksFactory creates a new CircuitBreakerHooksFactory.

func (CircuitBreakerHooksFactory[T]) New

func (f CircuitBreakerHooksFactory[T]) New() Hooks[T]

type Hooks

type Hooks[T any] interface {
	BeforeSend(ctx context.Context, cmd core.Cmd[T]) (context.Context, error)
	OnError(ctx context.Context, sentCmd SentCmd[T], err error)
	OnResult(ctx context.Context, sentCmd SentCmd[T], recvResult ReceivedResult,
		err error)
	OnTimeout(ctx context.Context, sentCmd SentCmd[T], err error)
}

Hooks defines an interface for customizing behavior during the command sending process. Implementations can provide hooks for events such as BeforeSend, OnError, OnResult, and OnTimeout.

type HooksFactory

type HooksFactory[T any] interface {
	New() Hooks[T]
}

HooksFactory provides a way to create new Hooks instances.

type NoopHooks

type NoopHooks[T any] struct{}

func (NoopHooks[T]) BeforeSend

func (h NoopHooks[T]) BeforeSend(ctx context.Context, cmd core.Cmd[T]) (
	context.Context, error)

func (NoopHooks[T]) OnError

func (h NoopHooks[T]) OnError(ctx context.Context, sentCmd SentCmd[T],
	err error)

func (NoopHooks[T]) OnResult

func (h NoopHooks[T]) OnResult(ctx context.Context, sentCmd SentCmd[T],
	recvResult ReceivedResult, err error)

func (NoopHooks[T]) OnTimeout

func (h NoopHooks[T]) OnTimeout(ctx context.Context, sentCmd SentCmd[T],
	err error)

type NoopHooksFactory

type NoopHooksFactory[T any] struct {
	// contains filtered or unexported fields
}

func (NoopHooksFactory[T]) New

func (f NoopHooksFactory[T]) New() Hooks[T]

type ReceivedResult

type ReceivedResult struct {
	Seq    core.Seq
	Size   int
	Result core.Result
}

type SentCmd

type SentCmd[T any] struct {
	Seq  core.Seq
	Size int
	Cmd  core.Cmd[T]
}

Jump to

Keyboard shortcuts

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