refactor(utils): move utils/atomic to goutils

This commit is contained in:
yusing
2025-10-09 01:07:47 +08:00
parent c3fa7c66a7
commit 8047067b2b
8 changed files with 15 additions and 58 deletions

View File

@@ -1,9 +0,0 @@
package atomic
import "sync/atomic"
type (
Bool = atomic.Bool
Int32 = atomic.Int32
Int64 = atomic.Int64
)

View File

@@ -1,35 +0,0 @@
package atomic
import (
"sync/atomic"
"github.com/bytedance/sonic"
)
type Value[T any] struct {
atomic.Value
}
func (a *Value[T]) Load() T {
if v := a.Value.Load(); v != nil {
return v.(T)
}
var zero T
return zero
}
func (a *Value[T]) Store(v T) {
a.Value.Store(v)
}
func (a *Value[T]) Swap(v T) T {
if v := a.Value.Swap(v); v != nil {
return v.(T)
}
var zero T
return zero
}
func (a *Value[T]) MarshalJSON() ([]byte, error) {
return sonic.Marshal(a.Load())
}