mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-06-08 19:33:35 +03:00
### Describe Your Changes after golang 1.23 it's enough just to stop timer, no need to drain a channel related issue https://github.com/VictoriaMetrics/VictoriaMetrics/issues/9721, but this is not a fix for it ### Checklist The following checks are **mandatory**: - [ ] My change adheres to [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/victoriametrics/contributing/#pull-request-checklist). - [ ] My change adheres to [VictoriaMetrics development goals](https://docs.victoriametrics.com/victoriametrics/goals/).
33 lines
608 B
Go
33 lines
608 B
Go
package timerpool
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
|
)
|
|
|
|
// Get returns a timer for the given duration d from the pool.
|
|
//
|
|
// Return back the timer to the pool with Put.
|
|
func Get(d time.Duration) *time.Timer {
|
|
if v := timerPool.Get(); v != nil {
|
|
t := v.(*time.Timer)
|
|
if t.Reset(d) {
|
|
logger.Panicf("BUG: active timer trapped to the pool!")
|
|
}
|
|
return t
|
|
}
|
|
return time.NewTimer(d)
|
|
}
|
|
|
|
// Put returns t to the pool.
|
|
//
|
|
// t cannot be accessed after returning to the pool.
|
|
func Put(t *time.Timer) {
|
|
t.Stop()
|
|
timerPool.Put(t)
|
|
}
|
|
|
|
var timerPool sync.Pool
|