Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReportProgressFromArraySync ¶
func ReportProgressFromArraySync[T any](progress *inspectionmetadata.TaskProgressMetadata, source []T, process func(int, T) error) error
ReportProgressFromArraySync reports progress of processing an array synchronously. It updates the given TaskProgress with the current count and percentage. The process function is called for each element in the source array. If the process function returns an error, the reporting stops and the error is returned.
Types ¶
type ProgressUpdator ¶
type ProgressUpdator struct {
Progress *inspectionmetadata.TaskProgressMetadata
Interval time.Duration
OnTick ProgressUpdatorOnTickFunc
// contains filtered or unexported fields
}
ProgressUpdator periodically updates a TaskProgress object at a specified interval. It uses a callback function to perform the update logic on each tick. A ProgressUpdator instance is intended for a single-use lifecycle and cannot be reused once started.
func NewProgressUpdator ¶
func NewProgressUpdator(progress *inspectionmetadata.TaskProgressMetadata, interval time.Duration, onTick ProgressUpdatorOnTickFunc) *ProgressUpdator
NewProgressUpdator creates and initializes a new ProgressUpdator.
func (*ProgressUpdator) Done ¶
func (p *ProgressUpdator) Done() error
Done stops the periodic updates and waits for the worker goroutine to complete. It returns an error if the updator was not started. Calling Done multiple times is idempotent.
func (*ProgressUpdator) Start ¶
func (p *ProgressUpdator) Start(ctx context.Context) error
Start begins the periodic updates. It invokes the OnTick callback immediately and then continues to call it at the specified interval until Done is called. It returns an error if the updator has already been started. A ProgressUpdator instance cannot be reused or restarted once started.
type ProgressUpdatorOnTickFunc ¶
type ProgressUpdatorOnTickFunc = func(tp *inspectionmetadata.TaskProgressMetadata)
ProgressUpdatorOnTickFunc is a function type that is called by ProgressUpdator on each tick to update the task progress.