|
|
@@ -148,7 +148,9 @@ func (f *Feed) Send(value interface{}) (nsent int) {
|
|
|
f.sendCases[i].Send = rvalue
|
|
|
}
|
|
|
|
|
|
- // Send until all channels except removeSub have been chosen.
|
|
|
+ // Send until all channels except removeSub have been chosen. 'cases' tracks a prefix
|
|
|
+ // of sendCases. When a send succeeds, the corresponding case moves to the end of
|
|
|
+ // 'cases' and it shrinks by one element.
|
|
|
cases := f.sendCases
|
|
|
for {
|
|
|
// Fast path: try sending without blocking before adding to the select set.
|
|
|
@@ -170,6 +172,7 @@ func (f *Feed) Send(value interface{}) (nsent int) {
|
|
|
index := f.sendCases.find(recv.Interface())
|
|
|
f.sendCases = f.sendCases.delete(index)
|
|
|
if index >= 0 && index < len(cases) {
|
|
|
+ // Shrink 'cases' too because the removed case was still active.
|
|
|
cases = f.sendCases[:len(cases)-1]
|
|
|
}
|
|
|
} else {
|