timelimiter

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultTimeoutDuration = time.Second

Variables

This section is empty.

Functions

func DecorateConsumer

func DecorateConsumer[T any](limiter TimeLimiter, fn func(T) error) func(T) error

func DecorateFunction

func DecorateFunction[T any, R any](limiter TimeLimiter, fn func(T) (R, error)) func(T) (R, error)

func DecorateRunnable

func DecorateRunnable(limiter TimeLimiter, fn func() error) func() error

func DecorateSupplier

func DecorateSupplier[T any](limiter TimeLimiter, fn func() (T, error)) func() (T, error)

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

func (*Config) String

func (config *Config) String() string

type ConfigBuilder

type ConfigBuilder func(*Config)

func WithTimeoutDuration

func WithTimeoutDuration(timeoutDuration time.Duration) ConfigBuilder

type Event

type Event interface {
	fmt.Stringer
	TimeLimiterName() string
	CreationTime() time.Time
	EventType() EventType
}

type EventListener

type EventListener interface {
	OnSuccessFunc(func(SuccessEvent)) EventListener
	OnTimeoutFunc(func(TimeoutEvent)) EventListener
	OnPanicFunc(func(PanicEvent)) EventListener
	DismissSuccessFunc(func(SuccessEvent)) EventListener
	DismissTimeoutFunc(func(TimeoutEvent)) EventListener
	DismissPanicFunc(func(PanicEvent)) EventListener

	OnSuccess(fn.Consumer[SuccessEvent]) EventListener
	OnTimeout(fn.Consumer[TimeoutEvent]) EventListener
	OnPanic(fn.Consumer[PanicEvent]) EventListener
	DismissSuccess(fn.Consumer[SuccessEvent]) EventListener
	DismissTimeout(fn.Consumer[TimeoutEvent]) EventListener
	DismissPanic(fn.Consumer[PanicEvent]) EventListener
}

type EventType

type EventType string
const (
	SUCCESS EventType = "SUCCESS"
	TIMEOUT EventType = "TIMEOUT"
	PANIC   EventType = "PANIC"
)

type Metrics

type Metrics interface {
	SuccessCount() uint64
	TimeoutCount() uint64
	PanicCount() uint64
}

type PanicEvent added in v0.4.1

type PanicEvent interface {
	Event
	Panic() any
}

type SuccessEvent added in v0.4.1

type SuccessEvent interface {
	Event
}

type TimeLimiter

type TimeLimiter interface {
	Name() string
	Metrics() Metrics
	EventListener() EventListener
	Execute(func() (any, error)) (any, error)
}

func NewTimeLimiter

func NewTimeLimiter(name string, configs ...ConfigBuilder) TimeLimiter

type TimeoutError

type TimeoutError struct {
	// contains filtered or unexported fields
}

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

type TimeoutEvent added in v0.4.1

type TimeoutEvent interface {
	Event
}

Jump to

Keyboard shortcuts

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