simplify task package implementation

This commit is contained in:
yusing
2025-01-01 06:07:32 +08:00
parent e7aaa95ec5
commit 1ab34ed46f
35 changed files with 547 additions and 600 deletions

View File

@@ -0,0 +1,30 @@
package atomic
import (
"encoding/json"
"sync/atomic"
)
type Value[T any] struct {
atomic.Value
}
func (a *Value[T]) Load() T {
return a.Value.Load().(T)
}
func (a *Value[T]) Store(v T) {
a.Value.Store(v)
}
func (a *Value[T]) Swap(v T) T {
return a.Value.Swap(v).(T)
}
func (a *Value[T]) CompareAndSwap(oldV, newV T) bool {
return a.Value.CompareAndSwap(oldV, newV)
}
func (a *Value[T]) MarshalJSON() ([]byte, error) {
return json.Marshal(a.Load())
}