mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 17:28:53 +02:00
refactor(utils): move utils/atomic to goutils
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
package atomic
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
type (
|
||||
Bool = atomic.Bool
|
||||
Int32 = atomic.Int32
|
||||
Int64 = atomic.Int64
|
||||
)
|
||||
@@ -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())
|
||||
}
|
||||
Reference in New Issue
Block a user