go-zero/core/syncx/once.go

12 lines
184 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package syncx
import "sync"
2021-05-10 00:09:00 +08:00
// Once returns a func that guarantees fn can only called once.
2020-07-26 17:09:05 +08:00
func Once(fn func()) func() {
once := new(sync.Once)
return func() {
once.Do(fn)
}
}