wp-go/safety/number.go

14 lines
208 B
Go
Raw Permalink Normal View History

2023-03-19 12:40:08 +00:00
package safety
import (
"golang.org/x/exp/constraints"
"sync/atomic"
)
func Counter[T constraints.Integer]() func() T {
var counter int64
return func() T {
return T(atomic.AddInt64(&counter, 1))
}
}