timeout

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package timeout provides a Timeout policy.

Index

Constants

This section is empty.

Variables

View Source
var ErrExceeded = errors.New("timeout exceeded")

ErrExceeded is returned when an execution exceeds a configured timeout.

Functions

This section is empty.

Types

type Timeout

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

Timeout is a Policy that cancels executions if they exceed a time limit. Any policies composed inside the timeout, such as retries, will also be canceled. If the execution is configured with a Context, a child context will be created for the execution and canceled when the Timeout is exceeded.

This type is concurrency safe.

func With

func With[R any](timeLimit time.Duration) Timeout[R]

With returns a new Timeout for execution result type R and the timeLimit. The Timeout will cancel executions if they exceed a time limit. Any policies composed inside the timeout, such as retries, will also be canceled. If the execution is configured with a Context, a child context will be created for the execution and canceled when the Timeout is exceeded.

type TimeoutBuilder

type TimeoutBuilder[R any] interface {
	// OnTimeoutExceeded registers the listener to be called when the timeout is exceeded.
	OnTimeoutExceeded(listener func(event failsafe.ExecutionDoneEvent[R])) TimeoutBuilder[R]

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

func Builder

func Builder[R any](timeLimit time.Duration) TimeoutBuilder[R]

Builder returns a TimeoutBuilder for execution result type R which builds Timeouts for the timeLimit. The Timeout will cancel executions if they exceed a time limit. Any policies composed inside the timeout, such as retries, will also be canceled. If the execution is configured with a Context, a child context will be created for the execution and canceled when the Timeout is exceeded.

Jump to

Keyboard shortcuts

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