improve(search): progress & retries
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
22
search/progress.go
Normal file
22
search/progress.go
Normal file
@@ -0,0 +1,22 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user