File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -39,13 +39,16 @@ func NewTimer(o Observer) *Timer {
39
39
40
40
// ObserveDuration records the duration passed since the Timer was created with
41
41
// NewTimer. It calls the Observe method of the Observer provided during
42
- // construction with the duration in seconds as an argument. ObserveDuration is
43
- // usually called with a defer statement.
42
+ // construction with the duration in seconds as an argument. The observed
43
+ // duration is also returned. ObserveDuration is usually called with a defer
44
+ // statement.
44
45
//
45
46
// Note that this method is only guaranteed to never observe negative durations
46
47
// if used with Go1.9+.
47
- func (t * Timer ) ObserveDuration () {
48
+ func (t * Timer ) ObserveDuration () time.Duration {
49
+ d := time .Since (t .begin )
48
50
if t .observer != nil {
49
- t .observer .Observe (time . Since ( t . begin ) .Seconds ())
51
+ t .observer .Observe (d .Seconds ())
50
52
}
53
+ return d
51
54
}
You can’t perform that action at this time.
0 commit comments