WithGC start the counter with gc automatically
()
| 53 | |
| 54 | // WithGC start the counter with gc automatically |
| 55 | func (this *Counter[T]) WithGC() *Counter[T] { |
| 56 | if this.gcTicker != nil { |
| 57 | return this |
| 58 | } |
| 59 | this.gcTicker = time.NewTicker(1 * time.Second) |
| 60 | goman.New(func() { |
| 61 | for range this.gcTicker.C { |
| 62 | this.GC() |
| 63 | } |
| 64 | }) |
| 65 | |
| 66 | return this |
| 67 | } |
| 68 | |
| 69 | // Increase key |
| 70 | func (this *Counter[T]) Increase(key uint64, lifeSeconds int) T { |