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

async

package
v1.37.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunWithProgress

func RunWithProgress[T comparable, R any](
	observer func(T),
	f func(*Progress[T]) (R, error),
) (R, error)

RunWithProgress runs a function with a background goroutine reporting and progress to an observer.

func RunWithProgressE

func RunWithProgressE[T comparable](
	observer func(T),
	f func(*Progress[T]) error,
) error

RunWithProgressE runs a function with a background goroutine reporting and progress to an observer.

Types

type Progress

type Progress[T comparable] struct {
	// contains filtered or unexported fields
}

Progress is a wrapper around a channel which can be used to report progress of an operation. The zero value of Progress is invalid. Use NewProgress to create a new instance.

func NewNoopProgress

func NewNoopProgress[T comparable]() *Progress[T]

NewNoopProgress creates a new instance of Progress that does not report any progress. The progress channel is drained

func NewProgress

func NewProgress[T comparable]() *Progress[T]

NewProgress creates a new instance of Progress.

func (*Progress[T]) Done

func (p *Progress[T]) Done()

Done closes the underlying channel, signaling no more progress will be reported. It is an error to call SetProgress after calling Done.

func (*Progress[T]) Progress

func (p *Progress[T]) Progress() <-chan T

Progress returns the read side of the underlying channel. The channel will be closed when [Done] is called, so a `range` loop may be used to consume all progress updates.

func (*Progress[T]) SetProgress

func (p *Progress[T]) SetProgress(progress T)

SetProgress reports progress to the channel.

func (*Progress[T]) SetProgressWithContext added in v1.36.0

func (p *Progress[T]) SetProgressWithContext(ctx context.Context, progress T) error

SetProgressWithContext reports progress or returns the context error if delivery is canceled. As with SetProgress, callers must finish sending before calling Done.

Jump to

Keyboard shortcuts

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