File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,9 @@ func (s *Sometimes) Do(f func()) {
61
61
(s .Every > 0 && s .count % s .Every == 0 ) ||
62
62
(s .Interval > 0 && time .Since (s .last ) >= s .Interval ) {
63
63
f ()
64
- s .last = time .Now ()
64
+ if s .Interval > 0 {
65
+ s .last = time .Now ()
66
+ }
65
67
}
66
68
s .count ++
67
69
}
Original file line number Diff line number Diff line change @@ -92,3 +92,18 @@ func TestSometimesNegative(t *testing.T) {
92
92
s .Do (func () {})
93
93
s .Do (func () {})
94
94
}
95
+
96
+ func BenchmarkSometimes (b * testing.B ) {
97
+ b .Run ("no-interval" , func (b * testing.B ) {
98
+ s := rate.Sometimes {Every : 10 }
99
+ for i := 0 ; i < b .N ; i ++ {
100
+ s .Do (func () {})
101
+ }
102
+ })
103
+ b .Run ("with-interval" , func (b * testing.B ) {
104
+ s := rate.Sometimes {Interval : time .Second }
105
+ for i := 0 ; i < b .N ; i ++ {
106
+ s .Do (func () {})
107
+ }
108
+ })
109
+ }
You can’t perform that action at this time.
0 commit comments