wm/src/bsp/cfg/helper.go
2023-06-11 09:26:55 -05:00

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)
}