diff --git a/core/service/servicegroup.go b/core/service/servicegroup.go index 9281fb299..280d120c7 100644 --- a/core/service/servicegroup.go +++ b/core/service/servicegroup.go @@ -1,9 +1,10 @@ package service import ( + "sync" + "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/proc" - "github.com/zeromicro/go-zero/core/syncx" "github.com/zeromicro/go-zero/core/threading" ) @@ -35,7 +36,7 @@ type ( // NewServiceGroup returns a ServiceGroup. func NewServiceGroup() *ServiceGroup { sg := new(ServiceGroup) - sg.stopOnce = syncx.Once(sg.doStop) + sg.stopOnce = sync.OnceFunc(sg.doStop) return sg } diff --git a/core/syncx/once.go b/core/syncx/once.go deleted file mode 100644 index 8915eca58..000000000 --- a/core/syncx/once.go +++ /dev/null @@ -1,11 +0,0 @@ -package syncx - -import "sync" - -// Once returns a func that guarantees fn can only called once. -func Once(fn func()) func() { - once := new(sync.Once) - return func() { - once.Do(fn) - } -} diff --git a/core/syncx/once_test.go b/core/syncx/once_test.go deleted file mode 100644 index 9e7fd71d3..000000000 --- a/core/syncx/once_test.go +++ /dev/null @@ -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) -}