dotj6816
2016-05-31 05:52
浏览 519
已采纳

Golang中的最终期限(time.Now())是什么?

I saw a lot d.deadline(time.Now()) in net package. From the name, I just guess it just set deadline on now, which has no meaning in network communication. So what is the purpose deadline(time.Now()) in golang?

图片转代码服务由CSDN问答提供 功能建议

我在网络软件包中看到了很多d.deadline(time.Now())。 顾名思义,我想它只是设定了截止日期,这对网络通信没有任何意义。 那么golang的最终期限(time.Now())是什么?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dth96108 2016-05-31 06:02
    已采纳

    This is the function you are referring to (net package, file dial.go). So, it returns the first deadline to come between the deadline set and the timeout set for the connection.

    67  // Return either now+Timeout or Deadline, whichever comes first.
    68  // Or zero, if neither is set.
    69  func (d *Dialer) deadline(now time.Time) time.Time {
    70      if d.Timeout == 0 {
    71          return d.Deadline
    72      }
    73      timeoutDeadline := now.Add(d.Timeout)
    74      if d.Deadline.IsZero() || timeoutDeadline.Before(d.Deadline) {
    75          return timeoutDeadline
    76      } else {
    77          return d.Deadline
    78      }
    79  }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题