poll

package
v0.0.0-...-059d9f2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package poll waits for a remote state by asking for it at a fixed interval.

The v6 API has no webhook: a build is finished when reading it says so. That is all this package knows. It has no notion of builds, versions or HTTP, so it can serve any wait; the caller supplies how to read the state, when the state is final and which errors are worth asking again.

Index

Constants

View Source
const (
	// DefaultInterval is the time between two reads. It is fixed, with no
	// backoff: builds settle in seconds and the API's rate limit is far above
	// what one CLI run asks for.
	DefaultInterval = 5 * time.Second
	// DefaultTimeout bounds one wait, that is, one call to Until.
	DefaultTimeout = 3 * time.Minute
)

Variables

View Source
var ErrTimeout = errors.New("timed out waiting")

ErrTimeout is what Until wraps when the timeout passes before done reports true.

Functions

func Until

func Until[T any](ctx context.Context, opt Options,
	fetch func(context.Context) (T, error),
	done func(T) (bool, error),
) (T, error)

Until reads with fetch, right away and then every Interval, until done reports true, ctx ends or the timeout passes.

It always returns the last value fetch read successfully, so the caller can say which state the wait ended in. The error is:

  • the error done returned, when done ended the wait with one;
  • the error of a read that Retryable does not accept;
  • ctx.Err() when ctx ends first;
  • ErrTimeout, wrapped with the error of the last read if it failed, when the timeout passes first.

A Retry-After longer than Interval is honoured: the next read waits for it, still bounded by the timeout.

Types

type Options

type Options struct {
	// Interval is the time between two reads; zero means DefaultInterval.
	Interval time.Duration
	// Timeout bounds the whole wait; zero means DefaultTimeout.
	Timeout time.Duration
	// Retryable decides whether a failed read is asked again. It returns
	// true to retry, with the delay the server asked for, or zero to retry on
	// the next interval. Nil means no error is retried.
	Retryable func(error) (retry bool, after time.Duration)
	// After replaces time.After, so tests run without sleeping.
	After func(time.Duration) <-chan time.Time
}

Options tunes a wait. The zero value is valid and means the defaults.

Jump to

Keyboard shortcuts

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