Skip to content

Commit

Permalink
Merge pull request #422 from openziti/add-swap-to-atomic-value
Browse files Browse the repository at this point in the history
Add swap to atomic value
  • Loading branch information
plorenz authored Dec 3, 2024
2 parents 1c830a1 + d8e809a commit e7bde0c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions concurrenz/atomic_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ func (self *AtomicValue[T]) Load() T {
func (self *AtomicValue[T]) CompareAndSwap(old, new T) bool {
return (*atomic.Value)(self).CompareAndSwap(old, new)
}

func (self *AtomicValue[T]) Swap(new T) T {
result := (*atomic.Value)(self).Swap(new)
var old T
if v, ok := result.(T); ok {
old = v
}
return old
}

0 comments on commit e7bde0c

Please sign in to comment.