18 lines
298 B
Go
18 lines
298 B
Go
package cfg
|
|
|
|
// Read from the refs of n modifiers with lock protection
|
|
func Read[T any, V any](fn func(*T) *V, xs ...*Modifier[T]) V {
|
|
for _, v := range xs {
|
|
if v == nil {
|
|
continue
|
|
}
|
|
v.mu.RLock()
|
|
vv := fn(&v.Ref)
|
|
v.mu.RUnlock()
|
|
if vv != nil {
|
|
return *vv
|
|
}
|
|
}
|
|
return *new(V)
|
|
}
|