in benchmark/internal_tcp_client.go [98:141]
func (c *internalTCPClient) makeCalls(latencies []time.Duration, f func() (call, error)) error {
n := len(latencies)
calls := make(map[uint32]*call, n)
for i := 0; i < n; i++ {
c, err := f()
if err != nil {
return err
}
calls[c.id] = &c
}
timer := time.NewTimer(c.opts.timeout)
// Use the original underlying slice for latencies.
durations := latencies[:0]
for {
if len(calls) == 0 {
return nil
}
timer.Reset(c.opts.timeout)
select {
case id, ok := <-c.responseIDs:
if !ok {
panic("expecting more calls, but connection is closed")
}
call, ok := calls[id]
if !ok {
panic(fmt.Errorf("received unexpected response frame: %v", id))
}
call.numFrames--
if call.numFrames != 0 {
continue
}
durations = append(durations, time.Since(call.started))
delete(calls, id)
case <-timer.C:
return tchannel.ErrTimeout
}
}
}