Add observerFunc to observe with a Gauge
This commit is contained in:
parent
8496756f6d
commit
e63845e3ce
|
@ -21,10 +21,15 @@ type Observer interface {
|
|||
Observe(float64)
|
||||
}
|
||||
|
||||
type observerFunc func(float64)
|
||||
|
||||
func (o observerFunc) Observe(value float64) {
|
||||
o(value)
|
||||
}
|
||||
|
||||
type Timer struct {
|
||||
begin time.Time
|
||||
observer Observer
|
||||
gauge Gauge
|
||||
}
|
||||
|
||||
func StartTimer() *Timer {
|
||||
|
@ -37,7 +42,7 @@ func (t *Timer) With(o Observer) *Timer {
|
|||
}
|
||||
|
||||
func (t *Timer) WithGauge(g Gauge) *Timer {
|
||||
t.gauge = g
|
||||
t.observer = observerFunc(g.Set)
|
||||
return t
|
||||
}
|
||||
|
||||
|
@ -45,7 +50,4 @@ func (t *Timer) Stop() {
|
|||
if t.observer != nil {
|
||||
t.observer.Observe(time.Since(t.begin).Seconds())
|
||||
}
|
||||
if t.gauge != nil {
|
||||
t.gauge.Set(time.Since(t.begin).Seconds())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue