自动在空闲时间执行定时任务

This commit is contained in:
GoEdgeLab
2024-04-17 13:10:55 +08:00
parent e7b70dd9b3
commit 7af6bfd536
13 changed files with 218 additions and 49 deletions

View File

@@ -3,6 +3,7 @@
package counters
import (
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
syncutils "github.com/TeaOSLab/EdgeNode/internal/utils/sync"
@@ -56,11 +57,11 @@ func (this *Counter[T]) WithGC() *Counter[T] {
return this
}
this.gcTicker = time.NewTicker(1 * time.Second)
go func() {
goman.New(func() {
for range this.gcTicker.C {
this.GC()
}
}()
})
return this
}