progress

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPublisherClosed = errors.New("progress publisher closed")

Functions

func Publish

func Publish(ctx context.Context, event Event) error

Publish emits a progress event to the context-bound publisher. Returns an error if publishing fails (context canceled, publisher closed, etc.). Most callers should use the Report* helpers which ignore errors.

func ReportError

func ReportError(ctx context.Context, stage Stage, err error)

ReportError emits a stage event with an error message. This is useful for communicating non-fatal errors during batching or pagination so users can decide whether to cancel or continue. Errors are silently ignored per the package error handling policy.

func ReportMessage

func ReportMessage(ctx context.Context, stage Stage, message string)

ReportMessage emits a stage event with a descriptive message. Errors are silently ignored per the package error handling policy.

func ReportStage

func ReportStage(ctx context.Context, stage Stage)

ReportStage emits a stage transition event. Errors are silently ignored per the package error handling policy.

func WithPublisher

func WithPublisher(ctx context.Context, pub Publisher) context.Context

Types

type Event

type Event struct {
	Stage   Stage
	Message string
	Done    bool
	Err     error
}

Event conveys progress for a long-running operation.

type Publisher

type Publisher interface {
	Publish(ctx context.Context, event Event) error
	Close(err error)
}

Publisher emits progress events to interested listeners.

func FromContext

func FromContext(ctx context.Context) (Publisher, bool)

func NewChannelPublisher

func NewChannelPublisher(buffer int) (Publisher, <-chan Event)

type Stage

type Stage string

Stage identifies the conceptual phase of an operation emitting progress events.

const (
	// StagePrepare indicates the preparation phase before main work begins.
	// Used for validation, configuration loading, and setup tasks.
	StagePrepare Stage = "prepare"

	// StageFetch indicates network or I/O operations to retrieve data.
	// Used for API calls, database queries, and file reads.
	StageFetch Stage = "fetch"

	// StageProcess indicates computation or transformation of data.
	// Used for parsing, filtering, aggregation, and business logic.
	StageProcess Stage = "process"

	// StageRender indicates formatting and output of results.
	// Used for template rendering, serialization, and display preparation.
	StageRender Stage = "render"
)

Jump to

Keyboard shortcuts

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