(duration time.Duration)
| 14 | } |
| 15 | |
| 16 | func newCounter(duration time.Duration) *counter { |
| 17 | zeroTimer := time.NewTimer(duration) |
| 18 | |
| 19 | // when duration is 0, drain the expire event here |
| 20 | // so that user will never get the event. |
| 21 | if duration == 0 { |
| 22 | <-zeroTimer.C |
| 23 | } |
| 24 | |
| 25 | return &counter{ |
| 26 | duration: duration, |
| 27 | zeroTimer: zeroTimer, |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | func (counter *counter) add(n int) int { |
| 32 | counter.mutex.Lock() |