wp-go/safety/number.go
2023-03-19 20:40:08 +08:00

14 lines
208 B
Go

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))
}
}