MCPcopy
hub / github.com/segmentio/kafka-go / timeout

Method timeout

client.go:125–142  ·  view source on GitHub ↗
(ctx context.Context, defaultTimeout time.Duration)

Source from the content-addressed store, hash-verified

123}
124
125func (c *Client) timeout(ctx context.Context, defaultTimeout time.Duration) time.Duration {
126 timeout := c.Timeout
127
128 if deadline, ok := ctx.Deadline(); ok {
129 if remain := time.Until(deadline); remain < timeout {
130 timeout = remain
131 }
132 }
133
134 if timeout > 0 {
135 // Half the timeout because it is communicated to kafka in multiple
136 // requests (e.g. Fetch, Produce, etc...), this adds buffer to account
137 // for network latency when waiting for the response from kafka.
138 return timeout / 2
139 }
140
141 return defaultTimeout
142}
143
144func (c *Client) timeoutMs(ctx context.Context, defaultTimeout time.Duration) int32 {
145 return milliseconds(c.timeout(ctx, defaultTimeout))

Callers 2

FetchMethod · 0.95
timeoutMsMethod · 0.95

Calls 1

DeadlineMethod · 0.80

Tested by

no test coverage detected