mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Initial commit
This commit is contained in:
26
vendor/github.com/markbates/oncer/oncer.go
generated
vendored
Normal file
26
vendor/github.com/markbates/oncer/oncer.go
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
package oncer
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var onces = &sync.Map{}
|
||||
|
||||
func Do(name string, fn func()) {
|
||||
o, _ := onces.LoadOrStore(name, &sync.Once{})
|
||||
if once, ok := o.(*sync.Once); ok {
|
||||
once.Do(log(name, fn))
|
||||
}
|
||||
}
|
||||
|
||||
func Reset(names ...string) {
|
||||
if len(names) == 0 {
|
||||
onces = &sync.Map{}
|
||||
return
|
||||
}
|
||||
|
||||
for _, n := range names {
|
||||
onces.Delete(n)
|
||||
onces.Delete(deprecated + n)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user