Skip to content

Commit 4b8b9aa

Browse files
committed
fix readability
1 parent b063898 commit 4b8b9aa

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

plexer.go

+23-22
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,33 @@ func (p *Plexer) Run() {
5252
return
5353
}
5454

55-
if !handledMsg {
56-
// if after ranging over all the channels we didn't have any work, that means
57-
// that there were no messages on any of the channels. We now want to block
58-
// here and wait for a message from ANY channel
55+
if handledMsg {
56+
continue
57+
}
5958

60-
cases := make([]reflect.SelectCase, 0, len(p.channels))
61-
for _, ch := range p.channels {
62-
if ch == nil {
63-
continue
64-
}
65-
cases = append(cases, reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(ch)})
59+
// if after ranging over all the channels we didn't have any work, that means
60+
// that there were no messages on any of the channels. We now want to block
61+
// here and wait for a message from ANY channel
62+
cases := make([]reflect.SelectCase, 0, len(p.channels))
63+
for _, ch := range p.channels {
64+
if ch == nil {
65+
continue
6666
}
67+
cases = append(cases, reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(ch)})
68+
}
6769

68-
remaining := len(cases)
69-
for remaining > 0 {
70-
chosen, value, ok := reflect.Select(cases)
71-
if !ok {
72-
// The chosen channel has been closed, so zero out the channel to disable the case
73-
cases[chosen].Chan = reflect.ValueOf(nil)
74-
remaining--
75-
continue
76-
}
77-
78-
p.output <- value.Bytes()
79-
break
70+
remaining := len(cases)
71+
for remaining > 0 {
72+
chosen, value, ok := reflect.Select(cases)
73+
if !ok {
74+
// The chosen channel has been closed, so zero out the channel to disable the case
75+
cases[chosen].Chan = reflect.ValueOf(nil)
76+
remaining--
77+
continue
8078
}
79+
80+
p.output <- value.Bytes()
81+
break
8182
}
8283
}
8384
}

0 commit comments

Comments
 (0)