Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/remote/vault/ticker.go
4096 views
1
package vault
2
3
import (
4
"time"
5
)
6
7
// ticker is a wrapper around time.Ticker which allows the tick time to be 0.
8
// ticker is not goroutine safe; do not call Chan at the same time as Reset.
9
type ticker struct {
10
ch <-chan time.Time
11
12
inner *time.Ticker
13
}
14
15
func newTicker(d time.Duration) *ticker {
16
var t ticker
17
t.Reset(d)
18
19
return &t
20
}
21
22
func (t *ticker) Chan() <-chan time.Time { return t.ch }
23
24
func (t *ticker) Reset(d time.Duration) {
25
if d == 0 {
26
t.Stop()
27
return
28
}
29
30
if t.inner == nil {
31
t.inner = time.NewTicker(d)
32
t.ch = t.inner.C
33
} else {
34
t.inner.Reset(d)
35
}
36
}
37
38
func (t *ticker) Stop() {
39
if t.inner != nil {
40
t.inner.Stop()
41
t.inner = nil
42
}
43
}
44
45