wm/src/bsp/cfg/helper.go

18 lines
298 B
Go
Raw Normal View History

2023-06-11 14:26:55 +00:00
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)
}