AnthoLume/search/progress.go
Evan Reichard 841b29c425
All checks were successful
continuous-integration/drone/push Build is passing
improve(search): progress & retries
2024-12-01 17:04:41 -05:00

23 lines
460 B
Go

package search
type writeCounter struct {
Total int64
Current int64
ProgressFunction func(float32)
}
func (wc *writeCounter) Write(p []byte) (int, error) {
n := len(p)
wc.Current += int64(n)
wc.flushProgress()
return n, nil
}
func (wc *writeCounter) flushProgress() {
if wc.ProgressFunction == nil || wc.Total < 100000 {
return
}
percentage := float32(wc.Current) * 100 / float32(wc.Total)
wc.ProgressFunction(percentage)
}