mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-06-30 14:06:39 +03:00
29 lines
482 B
Go
29 lines
482 B
Go
package timerpool
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// 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)
|
|
t.Reset(d)
|
|
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
|