Other: Linter fixes after bumping linter version

This commit is contained in:
James Houlahan
2022-10-11 18:04:39 +02:00
parent 4a5c411665
commit 14a578f319
23 changed files with 273 additions and 206 deletions

View File

@ -2,46 +2,46 @@ package safe
import "sync"
type Type[T any] struct {
type Value[T any] struct {
data T
lock sync.RWMutex
}
func NewType[T any](data T) *Type[T] {
return &Type[T]{
func NewValue[T any](data T) *Value[T] {
return &Value[T]{
data: data,
}
}
func (s *Type[T]) Get(fn func(data T)) {
func (s *Value[T]) Get(fn func(data T)) {
s.lock.RLock()
defer s.lock.RUnlock()
fn(s.data)
}
func (s *Type[T]) GetErr(fn func(data T) error) error {
func (s *Value[T]) GetErr(fn func(data T) error) error {
s.lock.RLock()
defer s.lock.RUnlock()
return fn(s.data)
}
func (s *Type[T]) Set(data T) {
func (s *Value[T]) Set(data T) {
s.lock.Lock()
defer s.lock.Unlock()
s.data = data
}
func GetType[T, Ret any](s *Type[T], fn func(data T) Ret) Ret {
func GetType[T, Ret any](s *Value[T], fn func(data T) Ret) Ret {
s.lock.RLock()
defer s.lock.RUnlock()
return fn(s.data)
}
func GetTypeErr[T, Ret any](s *Type[T], fn func(data T) (Ret, error)) (Ret, error) {
func GetTypeErr[T, Ret any](s *Value[T], fn func(data T) (Ret, error)) (Ret, error) {
s.lock.RLock()
defer s.lock.RUnlock()