deadline computes the effective deadline time based on context and timeout. It updates the usedAt timestamp to now. Uses cached time to avoid expensive syscall (max 50ms staleness is acceptable for deadline calculation).
(ctx context.Context, timeout time.Duration)
| 978 | // It updates the usedAt timestamp to now. |
| 979 | // Uses cached time to avoid expensive syscall (max 50ms staleness is acceptable for deadline calculation). |
| 980 | func (cn *Conn) deadline(ctx context.Context, timeout time.Duration) time.Time { |
| 981 | // Use cached time for deadline calculation (called 2x per command: read + write) |
| 982 | nowNs := getCachedTimeNs() |
| 983 | cn.SetUsedAtNs(nowNs) |
| 984 | tm := time.Unix(0, nowNs) |
| 985 | |
| 986 | if timeout > 0 { |
| 987 | tm = tm.Add(timeout) |
| 988 | } |
| 989 | |
| 990 | if ctx != nil { |
| 991 | deadline, ok := ctx.Deadline() |
| 992 | if ok { |
| 993 | if timeout == 0 { |
| 994 | return deadline |
| 995 | } |
| 996 | if deadline.Before(tm) { |
| 997 | return deadline |
| 998 | } |
| 999 | return tm |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | if timeout > 0 { |
| 1004 | return tm |
| 1005 | } |
| 1006 | |
| 1007 | return noDeadline |
| 1008 | } |
no test coverage detected