Documentation
¶
Overview ¶
Package dspc provides tools for tracking progress of concurrent operations in a terminal.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress tracks multiple named counters. It's similar to a concurrent map[string]int64 but optimized for progress tracking for a small stable sets of keys (typically fitting on a single screen).
All operations are atomic, lock-free and safe for concurrent use. Methods do not allocate memory in the hot path.
The zero Progress is empty and ready for use
func (*Progress) All ¶
All returns an iterator over all counters in lexicographical key order. The iterator yields (key, value) pairs. The values represent atomic snapshots of the counters at the time they are read.
func (*Progress) Get ¶
Get returns the current value of the counter associated with key. Returns 0 if the key doesn't exist.
func (*Progress) Inc ¶
Inc atomically adds delta to the counter associated with the given key. If the key doesn't exist, it's created with an initial value of 0 before adding delta.
func (*Progress) PrettyPrintEvery ¶
PrettyPrintEvery periodically prints the current state of Progress to w (typically stdout ot stderr). It updates the output in-place and won't damage the log output of the application (assuming logs are printed line by line). PrettyPrintEvery returns the function that stops the printing when called.
Usage:
stop := progress.PrettyPrintEvery(os.Stdout, time.Second, "Progress:") defer stop()
Or better:
defer progress.PrettyPrintEvery(os.Stdout, time.Second, "Progress:")()
Example output:
Progress: completed 15 failed 3 skipped 7