Remove Start() function, rename Stop() to Cancel()

This commit is contained in:
Ingo Oppermann
2024-10-28 17:12:31 +01:00
parent 412fbedea3
commit fbf62bf7e5
7 changed files with 40 additions and 76 deletions

View File

@@ -90,8 +90,7 @@ type cpuTimesStat struct {
}
type Util interface {
Start()
Stop()
Cancel()
// CPUCounts returns the number of cores, either logical or physical.
CPUCounts() (float64, error)
@@ -178,24 +177,18 @@ func New(root string, gpu psutilgpu.GPU) (Util, error) {
u.gpu = psutilgpu.NewNilGPU()
}
u.stopOnce.Do(func() {})
ctx, cancel := context.WithCancel(context.Background())
u.stopTicker = cancel
u.Start()
go u.tickCPU(ctx, time.Second)
go u.tickMemory(ctx, time.Second)
u.stopOnce = sync.Once{}
return u, nil
}
func (u *util) Start() {
u.startOnce.Do(func() {
ctx, cancel := context.WithCancel(context.Background())
u.stopTicker = cancel
go u.tickCPU(ctx, time.Second)
go u.tickMemory(ctx, time.Second)
})
}
func (u *util) Stop() {
func (u *util) Cancel() {
u.stopOnce.Do(func() {
u.stopTicker()