mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 00:40:00 +08:00
update:Use the official sync.OnceFunc (#4840)
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
package syncx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestOnce(t *testing.T) {
|
||||
var v int
|
||||
add := Once(func() {
|
||||
v++
|
||||
})
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
add()
|
||||
}
|
||||
|
||||
assert.Equal(t, 1, v)
|
||||
}
|
||||
|
||||
func BenchmarkOnce(b *testing.B) {
|
||||
var v int
|
||||
add := Once(func() {
|
||||
v++
|
||||
})
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
add()
|
||||
}
|
||||
assert.Equal(b, 1, v)
|
||||
}
|
||||
Reference in New Issue
Block a user