Skip to content

Commit

Permalink
com/: improve readability by removing redundant ifs
Browse files Browse the repository at this point in the history
In all cases both code paths do exactly the same.
  • Loading branch information
Al2Klimov committed Jul 8, 2024
1 parent c2d7928 commit 6c0248f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
18 changes: 6 additions & 12 deletions com/atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,18 @@ type Atomic[T any] struct {
v atomic.Value
}

func (a *Atomic[T]) Load() (_ T, ok bool) {
if v, ok := a.v.Load().(box[T]); ok {
return v.v, true
}

return
func (a *Atomic[T]) Load() (T, bool) {
v, ok := a.v.Load().(box[T])
return v.v, ok
}

func (a *Atomic[T]) Store(v T) {
a.v.Store(box[T]{v})
}

func (a *Atomic[T]) Swap(new T) (old T, ok bool) {
if old, ok := a.v.Swap(box[T]{new}).(box[T]); ok {
return old.v, true
}

return
func (a *Atomic[T]) Swap(new T) (T, bool) {
old, ok := a.v.Swap(box[T]{new}).(box[T])
return old.v, ok
}

func (a *Atomic[T]) CompareAndSwap(old, new T) (swapped bool) {
Expand Down
6 changes: 1 addition & 5 deletions com/com.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ func WaitAsync(w Waiter) <-chan error {
// If the channel is closed, it will return nil.
func ErrgroupReceive(g *errgroup.Group, err <-chan error) {
g.Go(func() error {
if e := <-err; e != nil {
return e
}

return nil
return <-err
})
}

Expand Down

0 comments on commit 6c0248f

Please sign in to comment.