diff --git a/internal/client/index.go b/internal/client/index.go index dc4b3fe6..63ae690e 100644 --- a/internal/client/index.go +++ b/internal/client/index.go @@ -337,14 +337,13 @@ func (ci *Index) Range(f func(c *Persistent) (cont bool)) { } } -// SortedRange is like [Index.Range] but sorts the keys before iterating -// ensuring a predictable order. -func (ci *Index) SortedRange( - s func(a, b *Persistent) (n int), - f func(c *Persistent) (cont bool), -) { +// RangeByName is like [Index.Range] but sorts the persistent clients by name +// before iterating ensuring a predictable order. +func (ci *Index) RangeByName(f func(c *Persistent) (cont bool)) { cs := maps.Values(ci.uidToClient) - slices.SortFunc(cs, s) + slices.SortFunc(cs, func(a, b *Persistent) (n int) { + return strings.Compare(a.Name, b.Name) + }) for _, c := range cs { if !f(c) { @@ -355,12 +354,8 @@ func (ci *Index) SortedRange( // CloseUpstreams closes upstream configurations of persistent clients. func (ci *Index) CloseUpstreams() (err error) { - sortFunc := func(a, b *Persistent) (n int) { - return strings.Compare(a.Name, b.Name) - } - var errs []error - ci.SortedRange(sortFunc, func(c *Persistent) (cont bool) { + ci.RangeByName(func(c *Persistent) (cont bool) { err = c.CloseUpstreams() if err != nil { errs = append(errs, err) diff --git a/internal/client/index_internal_test.go b/internal/client/index_internal_test.go index 782603ca..2a9314a8 100644 --- a/internal/client/index_internal_test.go +++ b/internal/client/index_internal_test.go @@ -125,14 +125,12 @@ func TestClientIndex(t *testing.T) { }) t.Run("sorted_range", func(t *testing.T) { - sortFunc := func(a, b *Persistent) (n int) { + slices.SortFunc(clients, func(a, b *Persistent) (n int) { return strings.Compare(a.Name, b.Name) - } - - slices.SortFunc(clients, sortFunc) + }) got := []*Persistent{} - ci.SortedRange(sortFunc, func(c *Persistent) (cont bool) { + ci.RangeByName(func(c *Persistent) (cont bool) { got = append(got, c) return true