79837743

Date: 2025-12-04 09:27:19
Score: 2
Natty:
Report link

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
}
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @flakes
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: bungulator