poll

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Poll

func Poll(ctx context.Context, cfg Config, fetch Fetcher) (string, error)

Poll calls fetch repeatedly until it returns done or an error. It calls fetch immediately on the first iteration (no initial wait).

func WithOnProgress added in v0.6.0

func WithOnProgress(ctx context.Context, fn OnProgress) context.Context

WithOnProgress attaches a progress callback to the context. When Poll is called without Config.OnProgress, it falls back to this.

Types

type Config

type Config struct {
	Interval    time.Duration // base polling interval
	MaxAttempts int           // 0 means unlimited
	Backoff     float64       // multiplier per attempt; 1.0 = fixed interval
	MaxInterval time.Duration // upper bound for backoff growth
	OnProgress  OnProgress    // optional progress callback
}

Config controls polling behavior.

type Fetcher

type Fetcher func(ctx context.Context) (result string, done bool, err error)

Fetcher checks whether an async task has completed. It returns the result string when done is true.

type OnProgress

type OnProgress func(attempt int, elapsed time.Duration)

OnProgress is called after each poll attempt (optional).

Jump to

Keyboard shortcuts

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