mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
Other: Linter fixes after bumping linter version
This commit is contained in:
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user