once.go 184 B

1234567891011
  1. package syncx
  2. import "sync"
  3. // Once returns a func that guanartees fn can only called once.
  4. func Once(fn func()) func() {
  5. once := new(sync.Once)
  6. return func() {
  7. once.Do(fn)
  8. }
  9. }