github.com/schparky/pop@v4.13.1+incompatible/internal/oncer/oncer.go (about) 1 package oncer 2 3 import ( 4 "sync" 5 ) 6 7 var onces = &sync.Map{} 8 9 func Do(name string, fn func()) { 10 o, _ := onces.LoadOrStore(name, &sync.Once{}) 11 if once, ok := o.(*sync.Once); ok { 12 once.Do(fn) 13 } 14 } 15 16 func Reset(names ...string) { 17 if len(names) == 0 { 18 onces = &sync.Map{} 19 return 20 } 21 22 for _, n := range names { 23 onces.Delete(n) 24 onces.Delete(deprecated + n) 25 } 26 }