github.com/lingyao2333/mo-zero@v1.4.1/core/syncx/once.go (about) 1 package syncx 2 3 import "sync" 4 5 // Once returns a func that guarantees fn can only called once. 6 func Once(fn func()) func() { 7 once := new(sync.Once) 8 return func() { 9 once.Do(fn) 10 } 11 }