diff --git a/broadcast.go b/broadcast.go index e3a6097..c4b4d7a 100644 --- a/broadcast.go +++ b/broadcast.go @@ -18,7 +18,7 @@ type broadcast struct { func newBroadcast(ctx context.Context, src <-chan ServerList) *broadcast { b := &broadcast{ ctx: ctx, - src: newServerListFilter(ctx, src), + src: filterEqualServerList(src), tgts: make(map[Listener]bool), add: make(chan Listener), rem: make(chan Listener), diff --git a/filter.go b/filter.go index f6a9494..184c58b 100644 --- a/filter.go +++ b/filter.go @@ -1,30 +1,17 @@ package main -import "context" - -func newServerListFilter(ctx context.Context, in <-chan ServerList) <-chan ServerList { +func filterEqualServerList(in <-chan ServerList) <-chan ServerList { out := make(chan ServerList) - go doFilter(ctx, in, out) - return out -} -func doFilter(ctx context.Context, in <-chan ServerList, out chan ServerList) { - var prev ServerList + go func() { + defer close(out) + + var prev ServerList -looping: - for { - select { - case <-ctx.Done(): - return - case next := <-in: + for next := range in { if len(prev) == len(next) { equal := true - // make a sacrifice for the ssa range check elimination gods - n := len(prev) - _ = prev[n-1] - _ = next[n-1] - for i := range prev { if !prev[i].Equal(next[i]) { equal = false @@ -33,12 +20,14 @@ looping: } if equal { - continue looping + continue } } prev = next out <- next } - } + }() + + return out }