Help us shape the future of Go! Take the 2026 Go Developer Survey

wait

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 8 Imported by: 57

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RetryHttpErrorStatusCodes = []int{http.StatusBadGateway, http.StatusGatewayTimeout}

Functions

This section is empty.

Types

type AsyncActionCheck

type AsyncActionCheck[T any] func() (waitFinished bool, response *T, err error)

AsyncActionCheck reports whether a specific async action has finished.

  • waitFinished == true if the async action is finished, false otherwise.
  • response contains data regarding the current state of the resource targeted by the async action, if applicable. If not applicable, T should be struct{}.
  • err != nil if there was an error checking if the async action finished, or if it finished unsuccessfully.

type AsyncActionHandler

type AsyncActionHandler[T any] struct {
	IntermediateStateReached bool
	// contains filtered or unexported fields
}

AsyncActionHandler handles waiting for a specific async action to be finished.

func New

func New[T any](f AsyncActionCheck[T]) *AsyncActionHandler[T]

New initializes an AsyncActionHandler

func (*AsyncActionHandler[T]) GetTimeout added in v0.24.0

func (h *AsyncActionHandler[T]) GetTimeout() time.Duration

func (*AsyncActionHandler[T]) SetSleepBeforeWait

func (h *AsyncActionHandler[T]) SetSleepBeforeWait(d time.Duration) *AsyncActionHandler[T]

SetSleepBeforeWait sets the duration for sleep before wait.

func (*AsyncActionHandler[T]) SetTempErrRetryLimit

func (h *AsyncActionHandler[T]) SetTempErrRetryLimit(l int) *AsyncActionHandler[T]

SetTempErrRetryLimit sets the retry limit if a temporary error is found. The list of temporary errors is defined in the RetryHttpErrorStatusCodes variable.

func (*AsyncActionHandler[T]) SetThrottle

func (h *AsyncActionHandler[T]) SetThrottle(d time.Duration) *AsyncActionHandler[T]

SetThrottle sets the time interval between each check of the async action.

func (*AsyncActionHandler[T]) SetTimeout

func (h *AsyncActionHandler[T]) SetTimeout(d time.Duration) *AsyncActionHandler[T]

SetTimeout sets the duration for wait timeout. This only has an effect, if there's no timeout/deadline set on the context.

func (*AsyncActionHandler[T]) WaitWithContext

func (h *AsyncActionHandler[T]) WaitWithContext(ctx context.Context) (res *T, err error)

WaitWithContext starts the wait until there's an error or wait is done

type WaiterHelper added in v0.23.0

type WaiterHelper[T any, S comparable] struct {
	// FetchInstance is called periodically to get the latest resource data.
	FetchInstance func() (*T, error)

	// GetState extracts the status string from the API response.
	GetState func(*T) (S, error)

	// ActiveState represents the terminal "Happy Path" (e.g. ACTIVE, READY, CREATED).
	ActiveState []S

	// ErrorState represents the terminal "Error Path" (e.g. FAILED, ERROR).
	ErrorState []S

	// DeleteHttpErrorStatusCodes defines codes treated as a successful deletion (default: 403, 404, 410).
	DeleteHttpErrorStatusCodes []int
}

WaiterHelper is a helper struct, which creates based on the configured attributes the AsyncActionCheck for wait.New

func (*WaiterHelper[T, S]) Wait added in v0.23.0

func (w *WaiterHelper[T, S]) Wait() AsyncActionCheck[T]

Jump to

Keyboard shortcuts

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