Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package utils
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/zero"
"sync"
"time"
)
// Ticker 类似于time.Ticker但能够真正地停止
type Ticker struct {
raw *time.Ticker
done chan zero.Zero
once sync.Once
C <-chan time.Time
}
// NewTicker 创建新Ticker
func NewTicker(duration time.Duration) *Ticker {
raw := time.NewTicker(duration)
return &Ticker{
raw: raw,
C: raw.C,
done: make(chan zero.Zero, 1),
}
}
// Next 查找下一个Tick
func (this *Ticker) Next() bool {
select {
case <-this.raw.C:
return true
case <-this.done:
return false
}
}
// Stop 停止
func (this *Ticker) Stop() {
this.once.Do(func() {
this.raw.Stop()
this.done <- zero.New()
})
}