We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2ce4c30 commit 8122af0Copy full SHA for 8122af0
1 file changed
common/atomic/typed.go
@@ -42,5 +42,9 @@ func (t *TypedValue[T]) Swap(new T) T {
42
}
43
44
func (t *TypedValue[T]) CompareAndSwap(old, new T) bool {
45
- return t.value.CompareAndSwap(typedValue[T]{old}, typedValue[T]{new})
+ return t.value.CompareAndSwap(typedValue[T]{old}, typedValue[T]{new}) ||
46
+ // In the edge-case where [atomic.Value.Store] is uninitialized
47
+ // and trying to compare with the zero value of T,
48
+ // then compare-and-swap with the nil any value.
49
+ (any(old) == any(common.DefaultValue[T]()) && t.value.CompareAndSwap(any(nil), typedValue[T]{new}))
50
0 commit comments