Skip to content

Commit

Permalink
Use time.Until(deadline) instead of -time.Since(deadline) (#1434)
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Nov 16, 2022
1 parent 8a60232 commit b32a3dd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client.go
Expand Up @@ -907,7 +907,7 @@ type clientURLResponse struct {
}

func clientGetURLDeadline(dst []byte, url string, deadline time.Time, c clientDoer) (statusCode int, body []byte, err error) {
timeout := -time.Since(deadline)
timeout := time.Until(deadline)
if timeout <= 0 {
return 0, dst, ErrTimeout
}
Expand Down Expand Up @@ -2361,7 +2361,7 @@ func (c *PipelineClient) DoDeadline(req *Request, resp *Response, deadline time.
func (c *pipelineConnClient) DoDeadline(req *Request, resp *Response, deadline time.Time) error {
c.init()

timeout := -time.Since(deadline)
timeout := time.Until(deadline)
if timeout < 0 {
return ErrTimeout
}
Expand Down
2 changes: 1 addition & 1 deletion fasthttputil/pipeconns.go
Expand Up @@ -266,7 +266,7 @@ func updateTimer(t *time.Timer, deadline time.Time) <-chan time.Time {
if deadline.IsZero() {
return nil
}
d := -time.Since(deadline)
d := time.Until(deadline)
if d <= 0 {
return closedDeadlineCh
}
Expand Down
2 changes: 1 addition & 1 deletion tcpdialer.go
Expand Up @@ -309,7 +309,7 @@ func (d *TCPDialer) dial(addr string, dualStack bool, timeout time.Duration) (ne
}

func (d *TCPDialer) tryDial(network string, addr *net.TCPAddr, deadline time.Time, concurrencyCh chan struct{}) (net.Conn, error) {
timeout := -time.Since(deadline)
timeout := time.Until(deadline)
if timeout <= 0 {
return nil, ErrDialTimeout
}
Expand Down

0 comments on commit b32a3dd

Please sign in to comment.