Thank you all for the suggestions and hints. I will definitely use @flakes idea of a loop condition and extracting the collecting part into its own function, since performCalls will have more logic in it. I know for a fact that nothing will close the more channel, so I think it is okay to not check for it, especially when every use of more is within ~20 lines of code. For the moment, I think this is what I will use:
func (a *Agent) collectCalls(call0 methodCall) []methodCall {
calls := []methodCall{call0}
for len(calls) < 200 {
select {
case call := <-a.more:
calls = append(calls, call)
default:
return calls
}
}
return calls
}
func (a *Agent) performCalls(call0 methodCall) {
defer func() { <-a.startSem }()
calls := a.collectCalls(call0)
// ... use calls
}