milvus-io--milvus
498b235461
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
52 行
1007 B
Go
52 行
1007 B
Go
package util
|
|
|
|
import "go.uber.org/atomic"
|
|
|
|
// Tickler counts every time when called inc(),
|
|
type Tickler struct {
|
|
count *atomic.Int32
|
|
total *atomic.Int32
|
|
closedSig *atomic.Bool
|
|
|
|
progressSig chan struct{}
|
|
}
|
|
|
|
func (t *Tickler) Inc() {
|
|
t.count.Inc()
|
|
t.progressSig <- struct{}{}
|
|
}
|
|
|
|
func (t *Tickler) SetTotal(total int32) {
|
|
t.total.Store(total)
|
|
}
|
|
|
|
// progress returns the count over total if total is set
|
|
// else just return the count number.
|
|
func (t *Tickler) Progress() int32 {
|
|
if t.total.Load() == 0 {
|
|
return t.count.Load()
|
|
}
|
|
return t.count.Load() * 100 / t.total.Load()
|
|
}
|
|
|
|
func (t *Tickler) Close() {
|
|
t.closedSig.CompareAndSwap(false, true)
|
|
}
|
|
|
|
func (t *Tickler) IsClosed() bool {
|
|
return t.closedSig.Load()
|
|
}
|
|
|
|
func (t *Tickler) GetProgressSig() chan struct{} {
|
|
return t.progressSig
|
|
}
|
|
|
|
func NewTickler() *Tickler {
|
|
return &Tickler{
|
|
count: atomic.NewInt32(0),
|
|
total: atomic.NewInt32(0),
|
|
closedSig: atomic.NewBool(false),
|
|
progressSig: make(chan struct{}, 200),
|
|
}
|
|
}
|