poll

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 4 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).

type TaskStatus added in v0.13.0

type TaskStatus int

TaskStatus represents the normalized status of an async task.

const (
	StatusPending   TaskStatus = iota // queued, not yet started
	StatusRunning                     // in progress
	StatusSuccess                     // completed successfully
	StatusFailed                      // completed with error
	StatusCancelled                   // cancelled by user or system
)

func MapStatus added in v0.13.0

func MapStatus(raw string) TaskStatus

MapStatus maps a raw status string from any engine API to a normalized TaskStatus. The mapping is case-insensitive and covers common variations across providers.

func (TaskStatus) Done added in v0.13.0

func (s TaskStatus) Done() bool

Done returns true if the status is terminal (success, failed, or cancelled).

func (TaskStatus) String added in v0.13.0

func (s TaskStatus) String() string

String returns a human-readable status name.

Jump to

Keyboard shortcuts

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