summaryrefslogtreecommitdiff
path: root/lib/textui/progress.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/textui/progress.go')
-rw-r--r--lib/textui/progress.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/textui/progress.go b/lib/textui/progress.go
index 68d986f..48a3901 100644
--- a/lib/textui/progress.go
+++ b/lib/textui/progress.go
@@ -7,9 +7,9 @@ package textui
import (
"context"
"fmt"
- "sync/atomic"
"time"
+ "git.lukeshu.com/go/typedsync"
"github.com/datawire/dlib/dlog"
)
@@ -26,7 +26,7 @@ type Progress[T Stats] struct {
cancel context.CancelFunc
done chan struct{}
- cur atomic.Value // Value[T]
+ cur typedsync.Value[T]
oldStat T
oldLine string
}
@@ -45,7 +45,7 @@ func NewProgress[T Stats](ctx context.Context, lvl dlog.LogLevel, interval time.
}
func (p *Progress[T]) Set(val T) {
- if p.cur.Swap(val) == nil {
+ if _, hadOld := p.cur.Swap(val); !hadOld {
go p.run()
}
}
@@ -56,8 +56,10 @@ func (p *Progress[T]) Done() {
}
func (p *Progress[T]) flush(force bool) {
- //nolint:forcetypeassert // It wasn't worth it to me (yet?) to make a typed wrapper around atomic.Value.
- cur := p.cur.Load().(T)
+ cur, ok := p.cur.Load()
+ if !ok {
+ panic("should not happen")
+ }
if !force && cur == p.oldStat {
return
}