forked from mirror/redis
internal/pool: use min nonzero deadline
This commit is contained in:
parent
f8704e4b6b
commit
c0e70ad31d
|
@ -82,19 +82,36 @@ func (cn *Conn) Close() error {
|
|||
}
|
||||
|
||||
func (cn *Conn) deadline(ctx context.Context, timeout time.Duration) time.Time {
|
||||
now := time.Now()
|
||||
cn.SetUsedAt(now)
|
||||
tm := time.Now()
|
||||
cn.SetUsedAt(tm)
|
||||
|
||||
if timeout > 0 {
|
||||
tm = tm.Add(timeout)
|
||||
}
|
||||
|
||||
if ctx != nil {
|
||||
tm, ok := ctx.Deadline()
|
||||
deadline, ok := ctx.Deadline()
|
||||
if ok {
|
||||
return tm
|
||||
if timeout == 0 {
|
||||
return deadline
|
||||
}
|
||||
return minNonzeroTime(deadline, tm)
|
||||
}
|
||||
}
|
||||
|
||||
if timeout > 0 {
|
||||
return now.Add(timeout)
|
||||
return tm
|
||||
}
|
||||
|
||||
return noDeadline
|
||||
}
|
||||
|
||||
func minNonzeroTime(a, b time.Time) time.Time {
|
||||
if a.IsZero() {
|
||||
return b
|
||||
}
|
||||
if b.IsZero() || a.Before(b) {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue