@@ -7,18 +7,19 @@ import (
7
7
)
8
8
9
9
// Throttle is an object that will perform exactly one action per duration.
10
+ // Do call the function f if a specified duration has passed
11
+ // since the last function f was called for this instance of Throttle.
12
+ // In other words, given
13
+ // var throttle = Throttle.New(time.Minute)
14
+ // if throttle.Do(f) is called multiple times within a minute, only the first call will invoke f,
15
+ // even if f has a different value in each invocation.
16
+ // Waiting for a minute or a new instance of Throttle is required for each function to execute.
10
17
type Throttler interface {
11
- // Do call the function f if a specified duration has passed
12
- // since the last function f was called for this instance of Throttle.
13
- // In other words, given
14
- // var throttle = Throttle.New(time.Minute)
15
- // if throttle.Do(f) is called multiple times within a minute, only the first call will invoke f,
16
- // even if f has a different value in each invocation.
17
- // Waiting for a minute or a new instance of Throttle is required for each function to execute.
18
18
Do (f func ())
19
19
}
20
20
21
- // New is create Throttler instance
21
+ // New create a new Throttler. The duration variable sets the
22
+ // duration to restrict Do function argument function f.
22
23
func New (duration time.Duration ) Throttler {
23
24
return & throttle {
24
25
duration : duration ,
0 commit comments