14 lines
208 B
Go
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))
|
||
|
}
|
||
|
}
|